// 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();
如果你的問題是關於如何在幕後完成綁定,那就有一個相當複雜的答案。
是的,我的問題是如何在幕後做。我需要一個想法如何獲取DataTextField中提供的值,然後將其綁定到ListItem.Text字段..也許一些鏈接顯示任何示例 - 我正在搜索和選擇.. –
您可能會看這篇文章:http:// msdn。 microsoft.com/en-us/magazine/cc163816.aspx。最後,它討論瞭如何在WebForms數據綁定中使用TypeDescriptors,並展示如何實現DataBinder.Eval函數。 –