且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-01-08 14:37:17

试试这个:



aspx页面:





< 表格 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 = 服务器 >

< / asp:ComboBox >
< / 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.