C# 禁用状态维护
我有一个gridview,它将在gridview中分页时保持复选框状态。为什么在我刷新页面时复选框仍然保持?如何在我刷新页面或向数据库提交数据后禁用复选框状态保持C# 禁用状态维护,c#,asp.net,webforms,C#,Asp.net,Webforms,我有一个gridview,它将在gridview中分页时保持复选框状态。为什么在我刷新页面时复选框仍然保持?如何在我刷新页面或向数据库提交数据后禁用复选框状态保持 private void savechkdvls() { ArrayList usercontent = new ArrayList(); int index = -1; foreach (GridViewRow gvrow in GrdRole.Rows) { index = Con
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();
}
你可以使用
ViewState.Clear();
Response.Redirect("~/PageXXX.aspx");
要清除视图状态是否意味着当您转到下一页时,复选框的值与上一页相同?现在我的问题是刷新页面后,我先前勾选的复选框仍然保持不变,我只想在分页gridview时维护复选框。知道如何清除/禁用viewstate吗?命令很简单,但我不确定您选择的方式是否是最佳做法:viewstate[控件名称]=null;这样,就可以用键ViewState清除会话变量。清除ViewState的命令是:ViewState.clear