绑定 DropDownList
注:ds为DataSet
DataTable table=ds.Tables["mytable"];
foreach(DataRow row in table.Rows)
{
mylist.Items.Add(new ListItem(row[1].ToString(),row[0].ToString()));
}
foreach(DataRow row in table.Rows)
{
mylist.Items.Add(new ListItem(row[1].ToString(),row[0].ToString()));
}
mylist.DataSource=ds.Tables["mytable"].DefaultView;
mylist.DataTextField="tname";
mylist.DataValueField="tid";
mylist.DataBind();
mylist.DataTextField="tname";
mylist.DataValueField="tid";
mylist.DataBind();
注:BindList()最好写在OnInit中
Web 窗体设计器生成的代码