复制代码 代码如下:

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

        /// <summary>

        /// Session�@取多�x框值

        /// </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分��r之前多�x框��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”);
        }

您可能感兴趣的文章:

  • GridView分页的实现以及自定义分页样式功能实例
  • GridView自定义分页的四种存储过程
  • C#自定义DataGridViewColumn显示TreeView
  • yii2.0之GridView自定义按钮和链接用法
  • GridView自定义删除操作的具体方法
  • 自定义GridView并且实现拖拽(附源码)
  • asp.net gridview自定义value值的代码
  • asp.net gridview分页:第一页 下一页 1 2 3 4 上一页 最末页
  • asp.net中的GridView分页问题
  • Android入门之ActivityGroup+GridView实现Tab分页标签的方法
  • 基于GridView和ActivityGroup实现的TAB分页(附源码)
  • GridView自定义分页实例详解(附demo源码下载)
声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。