0
我有一个gridview,它会维持复选框状态,同时在gridview中分页。为什么当我刷新页面时,复选框仍然会保持状态?如何在刷新页面或向数据库提交数据后禁用复选框状态维护?禁用状态维护
private void savechkdvls()
{
ArrayList usercontent = new ArrayList();
int index = -1;
foreach (GridViewRow gvrow in GrdRole.Rows)
{
index = Convert.ToInt32(GrdRole.DataKeys[gvrow.RowIndex].Value);
bool result = ((CheckBox)gvrow.FindControl("chkSelect")).Checked;
if (Session["chkditems"] != null)
usercontent = (ArrayList)Session["chkditems"];
if (result)
{
if (!usercontent.Contains(index))
usercontent.Add(index);
}
else
usercontent.Remove(index);
}
if (usercontent != null && usercontent.Count > 0)
Session["chkditems"] = usercontent;
}
private void chkdvaluesp()
{
ArrayList usercontent = (ArrayList)Session["chkditems"];
if (usercontent != null && usercontent.Count > 0)
{
foreach (GridViewRow gvrow in GrdRole.Rows)
{
int index = Convert.ToInt32(GrdRole.DataKeys[gvrow.RowIndex].Value);
if (usercontent.Contains(index))
{
CheckBox myCheckBox = (CheckBox)gvrow.FindControl("chkSelect");
myCheckBox.Checked = true;
}
}
}
}
if (!IsPostBack)
{
filldropdown();
Bind();
}
你的意思是,当你去到下一个页面,该复选框具有与前一页相同的值? – Ted
现在我的问题是我刷新页面后,我勾选的复选框以前仍然保持,我只想维护复选框,而我分页gridview.any想法如何清除/禁用视图状态? – KyLim
该命令很简单,但我不确定你选择的方式是否是最佳实践: 'Viewstate [“name of control”] = null;' – Ted