数据绑定DROPDOWNLIST数据表格并添加自定义值 [英] Databinding Dropdownlist with data table and adding custom value

查看:141
本文介绍了数据绑定DROPDOWNLIST数据表格并添加自定义值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是我的数据绑定的DropDownList与datatable.And我需要多一个项目添加到需要在selection..I的第一个项目已经试了很多办法,但没有工作的下拉列表。

  ddlCountry.Items.Add( - 选择---);
ddlCountry.DataTextField =国家;
ddlCountry.DataValueField =国家;
ddlCountry.DataSource = DT;
ddlCountry.DataBind();


解决方案

您页声明:

 < ASP:DropDownList的ID =ddlCountryAppendDataBoundItems =真=服务器>
    < ASP:ListItem的值=0文本=[选择]选定=真>< / ASP:ListItem的>
< / ASP:DropDownList的>AppendDataBoundItems =true是关键。

您code背后:

  ddlCountry.DataTextField =国家;
ddlCountry.DataValueField =国家;
ddlCountry.DataSource = DT;
ddlCountry.DataBind();

I am databinding my dropdownlist with a datatable.And I need to add one more item to the dropdown list which needs to be the first item in selection..I had tried many ways but nothing working.

ddlCountry.Items.Add("--Select--");
ddlCountry.DataTextField = "Country";
ddlCountry.DataValueField = "Country";
ddlCountry.DataSource = dt;
ddlCountry.DataBind();

解决方案

Your page declaration:

<asp:dropdownlist id="ddlCountry" AppendDataBoundItems="true" runat="server" >
    <asp:ListItem Value="0" Text="[ Select ]" Selected="True"></asp:ListItem>
</asp:dropdownlist>

AppendDataBoundItems="true" is the key.

Your code behind:

ddlCountry.DataTextField = "Country";
ddlCountry.DataValueField = "Country";
ddlCountry.DataSource = dt;
ddlCountry.DataBind();

这篇关于数据绑定DROPDOWNLIST数据表格并添加自定义值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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