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();
}
をクリアする
を使うことができるしていますか? – Ted
今私の問題は私がページをリフレッシュした後、チェックボックス私は以前にも維持しています、私はチェックボックスを維持したいと思いますが、私はgridview.anyのアイデアをクリアする/ viewstateを無効にする方法? – KyLim
コマンドはシンプルですが、あなたが選んだ方法がベストプラクティスであるかどうかわかりません: 'Viewstate [" name = control "] = null;' – Ted