DropDownList的反复数据值字段OnSelected感到困惑,并选择第一个,为什么? [英] DropDownList with repeated data value fields OnSelected get confused and chooses the first one why?

查看:176
本文介绍了DropDownList的反复数据值字段OnSelected感到困惑,并选择第一个,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前问题:我的DropDownList设有DataTextField =COLUMNS_NAMEDataValueField =DATA_TYPE属性时,DropDownList_SelectedIndexChanged()不保留的基础上选定的输入文本。但它保留从项目的列表

的第一个值

解决方案所需的:如何留住基础上,DATA_TYPE属性选择输入的文本? 我试图存储会话[DDLValue] = DropDownList.SelectedItem.Text ,但它始终保留了满足索引中的各自的DATA_TYPE present项目列表中的第一个值。

即。如果让我选择的E从以下DropDownList中输入保留在DropDownList中值为D

如何留住E

  COLUMN_NAME DATA_TYPE
十进制
b十进制
ç小数
ðINT
ËINT
˚FVARCHAR
摹VARCHAR
^ h VARCHAR
我为varchar
ĴVARCHAR

.aspx的code:

 < ASP:DropDownList的ID =DropDownList5=服务器的AutoPostBack =真OnSelectedIndexChanged =DropDownList5_SelectedIndexChanged的DataSourceID =MySqlDataSource>
< / ASP:DropDownList的>
< ASP:SqlDataSource的ID =MySqlDataSource=服务器>
< / ASP:SqlDataSource的>

C#code:

 保护无效的Page_Load(对象发件人,EventArgs的发送)
{
    如果(!的IsPostBack)
    {
        BindDropDownLists();
    }
}私人无效BindDropDownLists()
{
    MySqlDataSource.ConnectionString =连接;
    MySqlDataSource.SelectCommand =SELECT DATA_TYPE +'_'+转换(VARCHAR(10),ROW_NUMBER()OVER(ORDER BY DATA_TYPE))作为DATA_TYPE,COLUMN_NAME information_schema.columns在(TABLE_NAME ='结果'AND COLUMN_NAME IN('列1 ','列2','栏3'));    DropDownList5.DataTextField =COLUMN_NAME;
    DropDownList5.DataValueField =DATA_TYPE;
    DropDownList5.DataBind();}


解决方案

渲染后,您的下拉列表看起来像下面的需要使用独特的价值领域的正确选择

Current Issue: My DropDownList is provided with DataTextField="COLUMNS_NAME" DataValueField="DATA_TYPE" properties, the DropDownList_SelectedIndexChanged() does not retain the text based on the selected input. But it retains the first value from the list of items

Solution Required: How to Retain the selected input text based on the DATA_TYPE property ? I tried storing the Session["DDLValue"] = DropDownList.SelectedItem.Text but it always retains the first value from the list of items which satisfies the respective DATA_TYPE present in an Index.

i.e. if i choose "e" from The following DropDownList inputs the value retained in DropDownList is "d"

How to retain "e"

COLUMN_NAME  DATA_TYPE  
a            decimal
b            decimal
c            decimal
d            int
e            int
f            varchar
g            varchar  
h            varchar
i            varchar
j            varchar

Aspx Code:

<asp:DropDownList ID="DropDownList5" runat="server"  AutoPostBack="true" OnSelectedIndexChanged ="DropDownList5_SelectedIndexChanged" DataSourceID="MySqlDataSource">
</asp:DropDownList>
<asp:SqlDataSource ID="MySqlDataSource" runat="server">
</asp:SqlDataSource>

C# code:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        BindDropDownLists();
    }
}

private void BindDropDownLists()
{
    MySqlDataSource.ConnectionString = connection;
    MySqlDataSource.SelectCommand =  "SELECT DATA_TYPE + '_' + convert(varchar(10), ROW_NUMBER() OVER(ORDER BY DATA_TYPE ))as DATA_TYPE, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_NAME = 'RESULT' AND COLUMN_NAME IN ('Column1','column2','Column3'))";

    DropDownList5.DataTextField = "COLUMN_NAME";
    DropDownList5.DataValueField = "DATA_TYPE";
    DropDownList5.DataBind();

}

解决方案

After render , your drop down list is look like below , need to use unique value field for proper selection

这篇关于DropDownList的反复数据值字段OnSelected感到困惑,并选择第一个,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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