给 ASP.Net 中 DropDownList 的使用(设置值,读取数据源)
设置数据源
DropDownListWCustomerinfo.DataSource = MaintenanceRepair.BLL.Customer.GetInfo();
DropDownListWCustomerinfo.DataTextField = "CustomerName";
DropDownListWCustomerinfo.DataValueField = "ID";
DropDownListWCustomerinfo.DataBind();
取值:
this.DropDownList1.SelectedItem.Text //取文字 既是否
this.DropDownList1.SelectedValue.ToString() //取编号
设置默认值
this.DropDownList1.SelectedValue = 3; // 3是编号
this.DropDownList1.Items.FindByText(cm.WCustomerinfo).Selected = true; //cm.WCustomerinfo是文字
this.DropDownList1.Items.FindByValue("3").Selected = true; // 3是编号