你用这种方法本来就行不通的.
你可以采用以下这种方法,只是提供思想.在每个CheckBox动作中将CheckBox Checked为True的取它的所在行的ID,可以把它保存在ArrayList中.以后只需访问ArrayList就行啦

解决方案 »

  1.   

    for(int j=1;j<=dataGrid.PageCount;j++
    {
          dataGrid.CurrentPageIndes=i;
          for(int i=0;i<dataGird.Itsm.count;i++)
          {
             ........
           }
    }
      

  2.   

    我也不想那么做啊,
    可老板叫我那么做,没办法, 
     wuzhijie()的方法我做过,行不通的
      

  3.   

    http://www.cnblogs.com/aierong/archive/2004/07/04/21150.aspx
      

  4.   

    1.在PageIndexChanged事件方法

    this.GetChecked();
    this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
    this.BindGrid();//执行数据绑定的语句

    2.在GetChecked方法里

    if(object(ViewState["check"],null))
    ArrayList my=(AraayList)ViewState["check"];
    for(int i=0;i<dataGird.Itsm.count;i++)
    {
    ........
    if(checked)
    my.Add(主键值);
    }

    3.数据绑定的语句别忘了设置datakeyfiled,因为在viewstate里保存的是datakey的列表,到用的时候也是根据这个最后的用的时候根据自己的需要来增删,比如你可以回退到上面的页,而根据viewstate里面保存的值显示出已被选中的列,进行显示、更改等,或者有按纽触发处理事件时,也要先执行GetChecked事件,把本页中选中的也加进去,等等原理大概如此,自己写吧
      

  5.   

    呵呵,在第二步少写了一句,重新改一下
    2.在GetChecked方法里

    ArrayList my=null;
    if(object(ViewState["check"],null))
    my=(AraayList)ViewState["check"];
    else my=new ArrayList();
    for(int i=0;i<dataGird.Itsm.count;i++)
    {
    ........
    if(checked)
    my.Add(主键值);
    }
    ViewState["check"]=my;

      

  6.   

    用数据库或者在绑定的数据源上添加一个列记录CheckBox的值,这样在遍历的时候遍历这个数据源不要遍历DataGrid的Item!应该可以行的通!但是必须要让你的DataTable持久化(比如放到Session里面)。或者使用一个ArrayList记录点击过(CheckBox)的记录的关键字。把它保存在ViewState里面或者Session里面。遍历的时候遍历这个ArrayList就可以了!
      

  7.   

    我自己试了一下,结合itemdatabound,效果非常好噢,呵呵
                      private void GetChecked()
    {
    ArrayList my=null;
    if(!object.Equals(ViewState["check"],null))
    my=(ArrayList)ViewState["check"];
    else my=new ArrayList();
    foreach(DataGridItem  li in this.DataGrid1.Items)
    {
    CheckBox cb1=(CheckBox)li.FindControl("CheckBox1");
    if(cb1.Checked&&!my.Contains(this.DataGrid1.DataKeys[li.ItemIndex]))
    {
    my.Add(this.DataGrid1.DataKeys[li.ItemIndex]);
    }
    if((!cb1.Checked)&&my.Contains(this.DataGrid1.DataKeys[li.ItemIndex]))
    {
    my.Remove(this.DataGrid1.DataKeys[li.ItemIndex]);
    }
    }
    ViewState["check"]=my;
    }
    private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
    {
    this.GetChecked();
    this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
    this.BindGrid();
    }
    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
    {
    ArrayList al=(ArrayList)ViewState["check"];
    if(al!=null&&al.Contains(this.DataGrid1.DataKeys[e.Item.ItemIndex]))
    {
    CheckBox cb=(CheckBox)e.Item.FindControl("CheckBox1");
    cb.Checked=true;
    }
    }
    }
      

  8.   

    smilnet(笨笨) ( ) 的方法是可行的,我原来用的也是这样的方法,不过已经实现!
      

  9.   

    in the case,first you assure the data is preserved.
    i reserve the grid data in the session.
    so when i retrieve the grid,i will operation the session.
    List the follwing steps:
    DataTable dt = (datatable)session[yoursessionString];
    foreach(DataRow dr in dt.rows)
    {
       //your code
    }