更新时间: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 followingDropDownList1.Clear();
and then again bind the values. It will work.