dropdownlist的动态绑定数据然后怎么添加默认项“请选择”

dropdownlist的动态绑定数据然后怎么添加默认项“请选择”,第1张

有两种方法:一种是用dual表查空值,然后绑定。另一种是先动态绑定数据后,然后插入一列默认项。

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)

这个跟控件无关吧,只跟你设置的数据源有关。

只要你的数据库语句中加一个distinct就可以啦~

例如:

select distinct type

from 表

1.在.cs文件里写好方法,参数是DropDownList选择的公司ID

2.前台双击按钮,产生按钮事件,取得DropDOwnList选择的值DropDownList.SelectedValue,调用.cs文件里的方法,取得返回的值,例如,取得返回的Table

3.判断返回的Table是否为空,如果不为空,绑定GridView

this.GridView.DataSource = Table

this.GridView.DataBound()

纯手工制作,求采纳


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/7915802.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-11
下一篇 2023-04-11

发表评论

登录后才能评论

评论列表(0条)

保存