千家信息网

asp.net如何实现Gridview分页保存选项

发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,小编给大家分享一下asp.net如何实现Gridview分页保存选项,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!代码如下
千家信息网最后更新 2026年11月03日asp.net如何实现Gridview分页保存选项

小编给大家分享一下asp.net如何实现Gridview分页保存选项,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

代码如下:


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


/// Session獲取多選框值
///

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;
}

///


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

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分页保存选项"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

代码 篇文章 内容 不怎么 大部分 更多 知识 行业 资讯 资讯频道 频道 加多 参考 学习 帮助 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 百单网互联网科技有限公司怎么样 互联网佳科技有限公司 互联网科技工作委员会毛军 互联网科技深圳 齐家互联网科技有限公司 互联网科技大会案例 金融科技和互联网金融 镁科技互联网资讯平台 天速互联网络科技有限公司 字节跳动和互联网科技 互联网科技人工智能实验室 中天科技中国工业互联网 西安有哪些互联网高科技企业 吉林省码上互联网科技电话 北京天晋互联网科技有限公司 杭州科技互联网公司有哪些 河南商务圈互联网科技有限公司 科技互联网专业务虚会材料 宁波允成互联网科技有限公司 科技发展第三阶段互联网时代 广东猪兼强互联网科技有限公司 厦门中拓互联网络科技有限公司 北京禾田雨橡互联网科技 哈尔滨秒房互联网科技有限公司 成都玖崟互联网科技有限公司乐商圈怎么样 宁波青枫互联网科技有限公司 科技类公司包括互联网吗 高科技互联网发展前景如何 群盈汇互联网科技有限公司 中天科技中国工业互联网
0