手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >asp.net Gridview分页保存选项
asp.net Gridview分页保存选项
摘要:复制代码代码如下:#region//'Revision:1.00CreatedDate:2013/08/02CreatedID:Una[#1...

复制代码 代码如下:

#region //'Revision: 1.00 Created Date: 2013/08/02 Created ID: Una [#1300071]增加多選框

/// <summary>

/// Session獲取多選框值

/// </summary>

private void RememberOldValues()

{

ArrayList categoryIDList = new ArrayList();

string index = "";

foreach (GridViewRow row in gridView.Rows)

{

index = (string)gridView.DataKeys[row.RowIndex].Value;

bool result = ((CheckBox)row.FindControl("DeleteThis")).Checked;

// Check in the Session

if (Session["id"] != null)

categoryIDList = (ArrayList)Session["id"];

if (result)

{

if (!categoryIDList.Contains(index))

categoryIDList.Add(index);

}

else

categoryIDList.Remove(index);

}

if (categoryIDList != null && categoryIDList.Count > 0)

Session["id"] = categoryIDList;

}

/// <summary>

/// Session分頁時之前多選框為true

/// </summary>

private void RePopulateValues()

{

ArrayList categoryIDList = (ArrayList)Session["id"];

if (categoryIDList != null && categoryIDList.Count > 0)

{

foreach (GridViewRow row in gridView.Rows)

{

string index = (string)gridView.DataKeys[row.RowIndex].Value;

if (categoryIDList.Contains(index))

{

CheckBox myCheckBox = (CheckBox)row.FindControl("DeleteThis");

myCheckBox.Checked = true;

}

}

}

}

#endregion

复制代码 代码如下:

protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

RememberOldValues();

gridView.PageIndex = e.NewPageIndex;

BindData();

RePopulateValues();

}

复制代码 代码如下:

protected void btnSelect_Click(object sender, EventArgs e)

{

string items = "";

ArrayList categoryIDList = new ArrayList();

string index ="";

foreach (GridViewRow row in gridView.Rows)

{

index = (string)gridView.DataKeys[row.RowIndex].Value;

bool result = ((CheckBox)row.FindControl("DeleteThis")).Checked;

// Check in the Session

if (Session["id"] != null)

categoryIDList = (ArrayList)Session["id"];

if (result)

{

if (!categoryIDList.Contains(index))

categoryIDList.Add(index);

}

else

categoryIDList.Remove(index);

}

if (categoryIDList != null && categoryIDList.Count > 0)

for (int i = 0; i < categoryIDList.Count; i++)

{

items += categoryIDList[i] + ",";

}

items = items.Substring(0, items.Length - 1);

ScriptManager.RegisterStartupScript(this, this.GetType(), "", "check('" + items + "');", true);

Session.Remove("id");

}

【asp.net Gridview分页保存选项】相关文章:

asp.net 文章内容分页显示的代码

asp.net gridview代码绑定

asp.net 无限分类第1/3页

asp.net Google样式分页控件

asp.net gridview 72般绝技第1/2页

asp.net刷新本页面的六种方法

asp.net 两个不同页面的传值

asp.net 程序优化精选第1/2页

asp.net GridView和DataList实现鼠标移到行行变色

asp.net保存远程图片的代码

精品推荐
分类导航