禁用状态维护

时间:2016-07-08 07:45:10

标签: c# asp.net webforms

我有一个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();
    }

1 个答案:

答案 0 :(得分:-1)

您可以使用

ViewState.Clear();
Response.Redirect("~/PageXXX.aspx");

清除ViewState