如何将值与下拉列表绑定 [英] how to bind the value with dropdownlist

查看:89
本文介绍了如何将值与下拉列表绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我有下拉列表&我将我的数据表值绑定到它.

Dear All,

I have dropdownlist & i am binding my datatable values to it.

ddlMName.DataSource = objDS.Tables[0];
ddlMName.DataTextField = "MenuName";
ddlMName.DataValueField = "MenuID";
ddlMName.DataBind();
with addition of this i need to bind the following value to it
ddlMName.Items.Add(new ListItem("<<Select One>>", "-1"));



<<select one>>应该首先显示在下拉列表中&然后是数据表值.




<<select one>> should display in dropdownlist at first & then datatable values.


How can i do this?

推荐答案


试试这个,
您必须设置AppendDataBoundItems = True
Hi ,
try this one ,
You have to set AppendDataBoundItems = True
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True">
    <asp:ListItem Value="-1">--select on --</asp:ListItem>
</asp:DropDownList>


最好的问候
M.Mitwalli


Best Regards
M.Mitwalli


尝试这种方式

try this way

drpList.Items.Insert(0, new ListItem(String.Empty, "<<Select One>>"));
drpList.SelectedIndex = 0;



http://stackoverflow.com/questions/267064/asp- net-add-blank-item-at-top-of-dropdownlist [



http://stackoverflow.com/questions/267064/asp-net-add-blank-item-at-top-of-dropdownlist[^]


所需的值
<<选择一个>>"是-1

您可以这样做(小改变就是解决方案1)
As You Want Value Of
"<<Select One>>" is -1

You Can Do Like This(Small Change Is Sollution1)
drpList.Items.Insert(0, new ListItem("<<Select One>>","-1"));


论据在哪里


Where The Arguments are As

drpList.Items.Insert(index value,New ListItem(Text As String, Value As string))


这篇关于如何将值与下拉列表绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆