Question

I'm looking for a way how is it bound that data from DataSource can be accessed via Item property on ListControl Class.

Can anyone give me an example how properties from passed object to DataSource are bound to generic class ListItemCollection? How that translation can be done by a code?

The translation I'd like to see is from DataSet to ListItemCollection. Thanks in advance for any help.

Was it helpful?

Solution

// Setting up a dataset.  This dataset has no data; in real life you'd get the
// data from somewhere else, such as a database, and wouldn't need to build it.

DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("ID"));
dt.Columns.Add(new DataColumn("Description"));
ds.Tables.Add(dt);

// Creating a list box. You'd probably have this declared in your HTML and wouldn't need to
// create it.  

ListBox listBox1 = new ListBox();

listBox1.DataSource = ds.Tables[0];
listBox1.DataValueField = "ID";
listBox1.DataTextField = "Description";
listBox1.DataBind();

If your question is about how the binding is done behind the scenes, that has a fairly complex answer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top