eg1:
string selectQuery = "select null extattrid,null extattrname from dual union all select extattrid,extattrname from VExtAttrDetail where extattrsn in (22)"
DataSet ds=dboperReq.GetDSet(selectQuery)
ddlTrantype.DataTextField = "extattrname"
ddlTrantype.DataValueField="extattrid"
ddlTrantype.DataSource=ds.Tables[0].DefaultView
ddlTrantype.DataBind()
eg2:
string selectQuery = "select extattrid,extattrname from VExtAttrDetail where extattrsn in (22)"
DataSet ds=dboperReq.GetDSet(selectQuery)
ddlTrantype.DataTextField = "extattrname"
ddlTrantype.DataValueField="extattrid"
ddlTrantype.DataSource=ds.Tables[0].DefaultView
ddlTrantype.DataBind()
ddlTrantype.Items.Insert(0,new ListItem(" "," "))//或者ListItem it = new ListItem("请选择", "0")
//mydroplist.Items.Insert(0,it)或者 ListItem lt = new ListItem()
//lt.Text = "请选择"
//lt.Value = "00"
//lt.Selected = true
//ddp.Items.Add(lt)
先把两个属性设好:DropDownList1.DataTextField
=
"name"
//下拉框显示的数据
DropDownList1.DataValueField
=
"userid"//实际的值
然后再把数据源绑定在DropDownList1上。
有先后之分:先绑定ddl_Semester,然后在ddl_Semester的SelectedIndexChanged触发事件里再绑定ddl_Course。ddl_Semester的autoPostbank设置为true(允许自动会发)这才是最重要的。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)