jkali() 不是,但我好像找到答案了. // Create a DropDownList control. DropDownList DropList = new DropDownList(); // Set the properties for the DropDownList control. DropList.ID = "ColorList"; DropList.AutoPostBack = true; Place.Controls.Add(DropList); ICollection CreateDataSource() {
// Create a table to store data for the DropDownList control. DataTable dt = new DataTable();
// Define the columns of the table. dt.Columns.Add(new DataColumn("ColorTextField", typeof(String))); dt.Columns.Add(new DataColumn("ColorValueField", typeof(String)));
不知道怎样赋值才能把它显示出来..
l=new listitem();
l.text="1";
l.value="1";
dropdownlist.items.add(l);
你是不是要这样啊?
不是,但我好像找到答案了. // Create a DropDownList control.
DropDownList DropList = new DropDownList(); // Set the properties for the DropDownList control.
DropList.ID = "ColorList";
DropList.AutoPostBack = true; Place.Controls.Add(DropList);
ICollection CreateDataSource()
{
// Create a table to store data for the DropDownList control.
DataTable dt = new DataTable();
// Define the columns of the table.
dt.Columns.Add(new DataColumn("ColorTextField", typeof(String)));
dt.Columns.Add(new DataColumn("ColorValueField", typeof(String)));
// Populate the table with sample values.
dt.Rows.Add(CreateRow("White", "White", dt));
dt.Rows.Add(CreateRow("Silver", "Silver", dt));
dt.Rows.Add(CreateRow("Dark Gray", "DarkGray", dt));
dt.Rows.Add(CreateRow("Khaki", "Khaki", dt));
dt.Rows.Add(CreateRow("Dark Khaki", "DarkKhaki", dt));
// Create a DataView from the DataTable to act as the data source
// for the DropDownList control.
DataView dv = new DataView(dt);
return dv; }