如何为所有选中的复选框检索下拉列表中的值,并且 return 在未选中时默认为默认值?

How to retreive values in DropwnList for all selected chekboxes, and return to default when unchecked?

默认下拉列表值包括所有书籍的位置。当我 select 一个复选框时,下拉列表应该只填充那本书是 available.In 后端的位置,我的存储过程对于单个参数和多个值工作正常。

但在 UI 中,我只能获取一个复选框的位置,如果我单击第二个复选框,则下拉列表不包含第二个复选框的值。

此外,当我全部取消单击时,它应该 return 为默认值。 任何提示或帮助将不胜感激。

<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: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
}