回传清空复选框
本文关键字:复选框 清空 | 更新日期: 2023-09-27 18:17:31
有一个复选框列表,在页面加载时将数据绑定到该复选框列表。选择的项目必须保存在db中。但是当我点击提交时,复选框中的项目计数是0。如何解决这个问题?
不能使用会话变量,因为有多个服务器。
<asp:CheckBoxList ID="cbl" runat="server"
AppendDataBoundItems="true" DataTextField="type"
DataValueField="typeid" EnableViewState="true">
</asp:CheckBoxList>
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostback)
{
FillCheckboxList();
int count = cbl.Items.count; // can see 15 here
}
}
protected void btn_click(object sender, EventArgs e)
{
int count = cbl.Items.count; //Now 0 here
if(cbl.Items.count > 0)
{
//............
}
}
复选框列表没有其他地方被清空。
我也有这个问题:这是因为(正如在评论中提到的)viewstate被禁用的页面或父控件的CheckBoxList(并通过不禁用该viewstate修复)。