有一个checkboxlist,数据在页面加载中绑定到该列表。所选项目必须保存在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)
{
//............
}
}
没有其他地方清空复选框。
答案 0 :(得分:0)
我也有这个问题:这是因为(如评论中所述)视图状态被禁用了页面或CheckBoxList的父控件(并通过不禁用该视图状态来修复)。