Databound TextBoxes and CheckBoxes in ASP.NET
I recently made a fairly simple crud app in asp.net. User management was the theme, and a whoole lotta columns was supposed to be edited in a nice and tidy fashion. Of course the standard TextBox is not databindable and I ended up with approximately 200 lines looking like this:
txtName.Text = dataSource.ItemName;
And another 200 lines like this:
dataSource.ItemName = txtName.Text;
Of course, this sucks. I had enough and created a fairly simple extension of the standard Panel (DataPanel) and extensions of the TextBox and CheckBox to enable DataBinding. All I need to do now is to add DataTextBox'es to the DataPanel and set a DataSourceColumn property in each textbox to the according column in the datasource. The datasource is appended to the DataPanel and can be a DataSet, DataTable, DataView or DataRow.
This even enables iterating rows by altering the DataPanels SelectedItemIndex property. Finally, on postback you'll only have to reinstate the datasource and call Update() on the DataPanel to slam the changes into the datasource.
The source will show up on my GotDotNet samples shortly if you're interested (temp here).
Anyone got other solutions to this problem?