2016-07-08 20 views
0

私はgridviewを持っており、ページを更新するときにチェックボックスが維持されるようにgridview.whyでページング中のチェックボックスの状態を維持するでしょうか?ページをリフレッシュしたり、 ?状態維持を無効にする

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(); 
    } 
+0

をクリアする

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

を使うことができるしていますか? – Ted

+0

今私の問題は私がページをリフレッシュした後、チェックボックス私は以前にも維持しています、私はチェックボックスを維持したいと思いますが、私はgridview.anyのアイデアをクリアする/ viewstateを無効にする方法? – KyLim

+0

コマンドはシンプルですが、あなたが選んだ方法がベストプラクティスであるかどうかわかりません: 'Viewstate [" name = control "] = null;' – Ted

答えて

-1

あなたは、あなたが次のページに移動するとき、チェックボックスは、前のページと同じ値になっていることを意味するかのViewState

+0

この方法で、キー "ViewState"でセッション変数をクリアします。 ViewStateをクリアするコマンドは次のとおりです: 'ViewState.Clear()' – Ted

関連する問題