zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

asp.netGridview分页保存选项

ASP 分页 保存 选项 netGridview
2023-06-13 09:15:04 时间

复制代码代码如下:


#region//"Revision:1.00CreatedDate:2013/08/02CreatedID:Una[#1300071]增加多?框
       ///<summary>
       ///Session?取多?框值
       ///</summary>
       privatevoidRememberOldValues()
       {
           ArrayListcategoryIDList=newArrayList();
           stringindex="";
           foreach(GridViewRowrowingridView.Rows)
           {
               index=(string)gridView.DataKeys[row.RowIndex].Value;
               boolresult=((CheckBox)row.FindControl("DeleteThis")).Checked;

               //CheckintheSession
               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之前多?框??rue
       ///</summary>
       privatevoidRePopulateValues()
       {
           ArrayListcategoryIDList=(ArrayList)Session["id"];
           if(categoryIDList!=null&&categoryIDList.Count>0)
           {
               foreach(GridViewRowrowingridView.Rows)
               {
                   stringindex=(string)gridView.DataKeys[row.RowIndex].Value;
                   if(categoryIDList.Contains(index))
                   {
                       CheckBoxmyCheckBox=(CheckBox)row.FindControl("DeleteThis");
                       myCheckBox.Checked=true;
                   }
               }
           }
       }
       #endregion


复制代码代码如下:

protectedvoidgridView_PageIndexChanging(objectsender,GridViewPageEventArgse)
       {
           RememberOldValues();
           gridView.PageIndex=e.NewPageIndex;
           BindData();
           RePopulateValues();
       }

复制代码代码如下:
protectedvoidbtnSelect_Click(objectsender,EventArgse)
       {
           stringitems="";
           ArrayListcategoryIDList=newArrayList();
           stringindex="";
           foreach(GridViewRowrowingridView.Rows)
           {
               index=(string)gridView.DataKeys[row.RowIndex].Value;
               boolresult=((CheckBox)row.FindControl("DeleteThis")).Checked;

               //CheckintheSession
               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(inti=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");
       }