Reputation: 319
I have a dropdown box that lists authors names:
I need to have this box update with the selected value from a 2nd dropdown list.
This clears the values from the authors dropdown list but it does not update the box with the selected value from the 2nd dropdown list. What do I need to include to get the value of the lbAuthorList to display the selected value from DroopDownList1?
protected void update_SelectedItem(object sender, EventArgs e)
{
lbAuthorList.Items.Clear();
lbAuthorList.Text = DropDownList1.SelectedItem.Text;
}
<asp:DropDownList runat="server" ID="lbAuthors" style="float:left;"
DataSourceID="odsAuthorList" DataTextField="DisplayAuthorName" DataValueField="AuthorID"
onselectedindexchanged="lbUserList_SelectedIndexChanged"
AppendDataBoundItems="True" >
</asp:DropDownList>
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="True"
DataSourceID="SqlDataSource2" DataTextField="Display_AuthorName" EnableViewState="false"
DataValueField="Display_AuthorName" OnSelectedIndexChanged="update_SelectedItem" AutoPostBack="true">
</asp:DropDownList>
Upvotes: 0
Views: 1845
Reputation: 63065
You need to add new item to drop down list,
protected void update_SelectedItem(object sender, EventArgs e)
{
lbAuthorList.Items.Clear();
lbAuthorList.Items.Add(new ListItem(DropDownList1.SelectedItem.Text, DropDownList1.SelectedItem.Text));
lbAuthorList.Items.FindByValue(DropDownList1.SelectedItem.Text).Selected = true;
}
Upvotes: 1