我有一個從SQL查詢結果填充的下拉框。從dropdownlist1中選擇的值成功填充lbAuthors下拉列表。在測試過程中,我意識到dropdownlist1的第一條記錄永遠不會更新到lbAuthors下拉列表中。下面是一個例子:如果我在第二個下拉框(Frost,Kipling,Poe)中有三個作者姓名,則第一個名字--Frost--不會更新到第一個下拉框中。吉卜林或坡 - 但不是霜。下拉列表中的第一條記錄不會更新其他dropdownbox
我的問題是 - 我需要在我的活動中包含哪些內容以允許Frost(或任何第一個記錄)更新到第一個下拉框中? -
代碼隱藏:
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;
}
標記:
<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>
看看這個答案http://stackoverflow.com/a/19528881/791952 –