>Hi All, I've been binding WinForms controls to DataTables using the syntax shown below for years and wonder if there's a better way of doing it using a BindingSource - this is what I currently do
>
>
> this.txtLastAmendedUser.DataBindings.Add("Text", dt, "amend_user");
>
>
>where dt is a DataTable and "amend_user" is a field. I typically have a dozen or so controls on a form so it's quite a code intensive method. Is there a better / easier way of binding ?
If you've got a data source set up for the project you can do this in the designer:In the properties window for the control:
Expand (DataBindings) ;select (Advanced) and open the dialog.
Choose the property you want to bind (eg for a TextBox 'Text') then in the 'Binding' dropdown just select the Table/Field that you want.
Duh - just saw this was a web app so the above won't apply :-{
In ASP.NET you can do it in markup :
http://msdn.microsoft.com/en-us/library/bda9bbfx(vs.71).aspx