asp.net Gridview分页保存选项

 更新时间:2013年08月21日 15:19:53   作者:  
这篇文章介绍了asp.net Gridview分页保存选项,有需要的朋友可以参考一下

复制代码 代码如下:

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

相关文章

  • 伪静态web.config配置步骤

    伪静态web.config配置步骤

    web.config是asp.net一个重要的配置文件,本文将介绍如何利用web.config配置伪静态,步骤很详细,需要了解的朋友可以参考下
    2012-12-12
  • asp.net Request.ServerVariables[] 读解

    asp.net Request.ServerVariables[] 读解

    asp.net Request.ServerVariables[] 读解,学习.net的朋友可以参考下,方便获取服务器的一些信息。
    2011-08-08
  • asp.net DropDownList实现二级联动效果

    asp.net DropDownList实现二级联动效果

    这篇文章主要介绍了asp.net DroDownList实现二级联动效果的相关资料,需要的朋友可以参考下
    2016-02-02
  • Asp.net,C# 加密解密字符串的使用详解

    Asp.net,C# 加密解密字符串的使用详解

    本篇文章对Asp.net,C# 加密解密字符串的使用进行了详细的分析介绍,需要的朋友参考下
    2013-05-05
  • NET NativeAOT 用法指南

    NET NativeAOT 用法指南

    NativeAOT 是 .NET 中一个非常棒和强大的工具,有了 NativeAOT,你可以以可预测的性能构建你的应用,同时节省资源(更低的内存占用和更小的二进制大小),本文介绍NET NativeAOT 指南,感兴趣的朋友一起看看吧
    2024-02-02
  • .Net整合Json实现REST服务客户端的方法详解

    .Net整合Json实现REST服务客户端的方法详解

    这篇文章主要给大家介绍了关于.Net整合Json实现REST服务客户端的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
    2018-01-01
  • ASP.NET Eval 求值运算的一些用法

    ASP.NET Eval 求值运算的一些用法

    ASP.NET Eval 求值运算的一些用法,需要的朋友可以参考下。
    2011-10-10
  • asp.net实现C#绘制太极图的方法

    asp.net实现C#绘制太极图的方法

    这篇文章主要介绍了asp.net实现C#绘制太极图的方法,实例分析了asp.net绘制图形的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-02-02
  • .NetCore使用Swagger+API多版本控制的流程分析

    .NetCore使用Swagger+API多版本控制的流程分析

    这篇文章主要介绍了.NetCore使用Swagger+API多版本控制的流程分析,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-12-12
  • 获取创建Membership的数据库创建脚本

    获取创建Membership的数据库创建脚本

    membership的数据库可以通过aspnet_regsql.exe来配置生成,但是里面的东西,不一定都是我需要的,有时我也想自定义一些东西。
    2010-02-02

最新评论