How can I dynamically bind data from a data set to a control?
For example, I have a dataset...
Dataset ds = new Dataset();
ds.ReadXML("file.xml");
and I want to bind a textbox to a specific row and column of that dataset, kind of like this:
textbox.bind(ds.tables["person"].rows[0]["name"];
I know the above code is incorrect, but is there anything like it that would allow me to bind a control dynamically?
Loading
Martin CookPosted Feb 10, 2010, 6:46 AM
Ideally, you would create a class model of your data, populate that from the database, and bind your view to the appropriate properties.
So your class might look something like this: -
pubic class Person : INotifyPropertyChanged
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; OnPropertyChanged("Name"); }
}
}
And your xaml would look something like this: -
Hopefully this will help you.
Cheers,
Martin
Sam HobbsPosted Jan 17, 2010, 12:20 PM
Create a data source and in the data source provide the SQL you need to retrieve the data. Then simply in the data source specify that you want a textbox for the field, but I think a textbox will be the default and you don't need to do that part. You will need to change the data source so that it creates a detail control instead of multiple. Then drag and drop the datasource to the form and you are done.