DropDownList使用方法:
和 datatable 绑定
(1)
datatable dt = new datatable();
this.DropDownList.DataSource = dt;
this.DropDownList.DataValueField = "Type_ID";
this.DropDownList.DataTextField = "Type_Name";
this.DropDownList.DataBind();
this.DropDownList.Items.Add(new ListItem("请选择",""));
(2)
datatable dt = new datatable();
this.DropDownList.Items.Add(new ListItem("---请选择---",""));
if(dt.Rows.count > 0)
{
foreach(DataRow dr in dt.Rows)
{
this.DropDownList.Items.Add(new ListItem(dr["Type_name"].ToString(),dr["Type_ID"].ToString()));
}
}
和 对象数组绑定
(1)
NAV_INFOTYPEINFO[] infomodels = Select();
this.DropDownList.DataSource = infomodels;
this.DropDownList.DataTextField = "Type_Name";
this.DropDownList.DataValueField = "Type_ID";
this.DropDownList.DataBind();
this.DropDownList.Items.Add(new ListItem("请选择",""));
(2)
NAV_INFOTYEPINFO[] infomodels = Select();
this.DropDownList.Items.Add(new ListItem("---请选择---",""));
if(infomodels.Length > 0)
{
foreach(NAV_INFOTYPEINFO infomodel in infomodels)
{
this>DropDownList.Items.Add(new ListItem(infomodel.Type_Name.toString(),infomodel.Type_ID.toString()));
}
}
和 datatable 绑定
(1)
datatable dt = new datatable();
this.DropDownList.DataSource = dt;
this.DropDownList.DataValueField = "Type_ID";
this.DropDownList.DataTextField = "Type_Name";
this.DropDownList.DataBind();
this.DropDownList.Items.Add(new ListItem("请选择",""));
(2)
datatable dt = new datatable();
this.DropDownList.Items.Add(new ListItem("---请选择---",""));
if(dt.Rows.count > 0)
{
foreach(DataRow dr in dt.Rows)
{
this.DropDownList.Items.Add(new ListItem(dr["Type_name"].ToString(),dr["Type_ID"].ToString()));
}
}
和 对象数组绑定
(1)
NAV_INFOTYPEINFO[] infomodels = Select();
this.DropDownList.DataSource = infomodels;
this.DropDownList.DataTextField = "Type_Name";
this.DropDownList.DataValueField = "Type_ID";
this.DropDownList.DataBind();
this.DropDownList.Items.Add(new ListItem("请选择",""));
(2)
NAV_INFOTYEPINFO[] infomodels = Select();
this.DropDownList.Items.Add(new ListItem("---请选择---",""));
if(infomodels.Length > 0)
{
foreach(NAV_INFOTYPEINFO infomodel in infomodels)
{
this>DropDownList.Items.Add(new ListItem(infomodel.Type_Name.toString(),infomodel.Type_ID.toString()));
}
}