首页 > 解决方案 > How to retreive values in DropwnList for all selected chekboxes, and return to default when unchecked?

问题描述

Default dropdownlist values include locations for all books. When I select a checkbox the the dropdownlist should populate only the locations where that book is available.In back-end, My Stored procedure is working fine for single parameter and multiple values.

But in UI, I can get locations for only one checkbox, if I click second checkbox the dropdown list does not include the value for that second checkbox.

Also when I unclick all it should return to default. Any hint or help will be appreciated.

<label>BooksLocations</label>
<asp:DropDownList runat="server" ID="drpdwnListLocationBooks" CssClass="formcontrol">                               
</asp:DropDownList>

<label>Books</label>
<asp:CheckBoxList runat="server" ID="chkboxListbookStatus">
    <asp:ListItem Text="Book A"></asp:ListItem>
    <asp:ListItem Text="Book B"></asp:ListItem>
    <asp:ListItem Text="Book C"></asp:ListItem>
</asp:CheckBoxList>

标签: asp.netado.net

解决方案


添加以下代码

<asp:CheckBoxList runat="server" ID="chkboxListbookStatus"  
 AutoPostBack="True" OnSelectedIndexChanged="chkboxListbookStatus_SelectedIndexChanged">

然后在后面的代码中

protected void chkboxListbookStatus_SelectedIndexChanged(object sender, EventArgs e)
{
  CheckBoxList list = sender as CheckBoxList;
  ListItem box = list.SelectedItem;
  //add code to get data from SP to fill data in dropdown
}

推荐阅读