选择一个下拉值将值绑定到组合框并选择另一个下拉值将值绑定到相同的组合框但以前的值没有更改....? [英] Select one dropdown value bind the values to combo box and select another dropdown value bind the values to same combo box but previous values are no changes ....?

查看:58
本文介绍了选择一个下拉值将值绑定到组合框并选择另一个下拉值将值绑定到相同的组合框但以前的值没有更改....?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

选择一个下拉值将值绑定到组合框并选择另一个下拉值将值绑定到相同的组合框但先前的值没有更改....?

解决方案

试试这个:



aspx页面:





< pre lang =xml> < 表格 id = form1 < span class =code-attribute> runat = server >
< div >
< asp:DropDownList ID = DropDownList1 < span class =code-attribute> runat = server AutoPostBack = True

< span class =code-attribute> onselectedindexchanged = DropDownList1_SelectedIndexChanged >
< asp:ListItem > Akil < / asp:ListItem < span class =code-keyword>>
< asp:ListItem > Arun < / asp:ListItem >
< asp :ListItem > Balu < / asp:ListItem >
< asp:ListItem > < / asp:ListItem >
< / asp:DropDownList >
< br / >
< br / >
< br / >
< asp:ComboBox < span class =code-attribute> ID = ComboBox1 runat = 服务器 >

< / asp:ComboBox >
< span class =code-keyword>< / div >
< / form >







aspx.cs:





  int  i =  0 ; 
受保护 void Page_Load( object sender,EventArgs e)
{

}
protected void DropDownList1_SelectedIndexChanged( object sender,EventArgs e)
{
ComboBox1.Items.Insert(i,DropDownList1.SelectedItem.Text);
i ++;
}


在绑定值之前,请写下以下内容



 DropDownList1.Clear(); 





然后再次绑定值。它会起作用。


Select one dropdown value bind the values to combo box and select another dropdown value bind the values to same combo box but previous values are no changes ....?

解决方案

try this:

aspx page:


<form id="form1" runat="server">
<div>
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"

        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
        <asp:ListItem>Akil</asp:ListItem>
        <asp:ListItem>Arun</asp:ListItem>
        <asp:ListItem>Balu</asp:ListItem>
        <asp:ListItem></asp:ListItem>
    </asp:DropDownList>
    <br />
    <br />
    <br />
    <asp:ComboBox ID="ComboBox1" runat="server" >

    </asp:ComboBox>
</div>
</form>




aspx.cs:


int i = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ComboBox1.Items.Insert(i,DropDownList1.SelectedItem.Text);
        i++;
    }


Before binding values just write the following

DropDownList1.Clear();



and then again bind the values. It will work.


这篇关于选择一个下拉值将值绑定到组合框并选择另一个下拉值将值绑定到相同的组合框但以前的值没有更改....?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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