asp.net Gridview分页保存选项

所属分类: 网络编程 / ASP.NET 阅读数: 784
收藏 0 赞 0 分享

复制代码 代码如下:

#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");
        }

更多精彩内容其他人还在看

MVC数据验证详解

这篇文章主要为大家详细介绍了MVC数据验证的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

MVC异常处理详解

这篇文章主要为大家详细介绍了MVC异常处理的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

PHP session实现购物车功能

这篇文章主要为大家详细介绍了PHP session实现购物车功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

vs2010出现error MSB8008的解决方法

这篇文章主要为大家详细介绍了vs2010问题error MSB8008: 指定的平台工具集(v110)未安装或无效的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

SqlDataReader指定转换无效的解决方法

这篇文章主要为大家详细介绍了SqlDataReader指定转换无效的解决方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

Asp.Net Core简介与安装教程

这篇文章主要为大家详细介绍了Asp.Net Core简介与安装教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

.Net Core+Angular Cli/Angular4开发环境搭建教程

这篇文章主要为大家详细介绍了.Net Core+Angular Cli/Angular4开发环境搭建教程,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

.Net MVC实现长轮询

这篇文章主要为大家详细介绍了.Net MVC实现长轮询的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

使用微信PC端的截图dll库实现微信截图功能

这篇文章主要为大家详细介绍了使用微信PC端的截图dll库实现微信截图功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

ASP.Net MVC+Data Table实现分页+排序功能的方法

这篇文章主要介绍了ASP.Net MVC+Data Table实现分页+排序功能的方法,结合实例形式分析了asp.net基于mvc架构实现的数据查询、排序、分页显示等相关操作技巧,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多