dropdownlist在后台从数据库中读取赋值:
//仓库名称下拉框的值
DataSet ds = stock.GetNameInfo();
DataTable dtWarehouseName = ds.Tables[0];
DataRow drWarehouseName = dtWarehouseName.NewRow();
drWarehouseName["WarehouseName"] = "请选择";
drWarehouseName["WarehouseID"] = "0";
dtWarehouseName.Rows.InsertAt(drWarehouseName, 0);
dtWarehouseName.AcceptChanges();
ddlWarehouse.DataSource = dtWarehouseName;
ddlWarehouse.DataTextField = "WarehouseName";
ddlWarehouse.DataValueField = "WarehouseID";
ddlWarehouse.DataBind();
手动添加项:
DropDownList ddl = new DropDownList();
ddl.Items.Add(new ListItem("北京", "1"));
ddl.Items.Add(new ListItem("上海", "2"));
ddl.Items.Add(new ListItem("广州", "3"));
在后台选中Dropdownlist的某一项
ListItem item = list.Items.FindByText("设备发放库");
if (item != null) item.Selected = true;
var ddlUseType = document.getElementById('<%=ddlUseType.ClientID %>'); //用途类别
var ddlUseTypeValue = ddlUseType.options[ddlUseType.selectedIndex].value;
if (ddlUseTypeValue == "0" && btnID != "btn1" && btnID != "btn8") {
openAlertDialog("请选择用途类别!");
return false;
}
if ($("#ddlUseType").val() == "0" && btnID != "btn1" && btnID != "btn8") {
openAlertDialog("请选择业务类别!");
return false;
}
if ($("#ddlUseType").find(":selected").text() == "请选择" && btnID != "btn1" && btnID != "btn8") {
openAlertDialog("请选择用途类别!");
return false;
}