除非你保存CheckBox 的选中状态,否则是无法在翻页时保持CheckBox Check的状态的

解决方案 »

  1.   

    OnCheckChanged事件中保存选中状态
      

  2.   

    不知道你怎么嵌套的checkbox 如果是服务器控件用ViewState应该可以,如果是用SQL拼装出来的。就要写javascript了
      

  3.   

    我用的笨办法,就是先把那些选中了的CheckBox的标识保存起来,然后页面跳转后,重新绑定,然后选中那些CheckBox
      

  4.   

    在页面提交时候,触发Page_Load事件,在该事件中加入:if (!IsPostBack)
    {
      数据绑顶...
    }
      

  5.   

    private void SetViewData()
    {
    string strSQL,strYear;
    DataTable dt; strYear=dblistYear.SelectedValue;
    string usercode=Session["user_code"].ToString();
    UserClass user=new UserClass(usercode);
    user.GetUserInfo(usercode);
    if(user.strDWDM!="H01")
    {
    strSQL="select code,name from jc_jddw where code ='"+user.strDWDM+"'";

    }
    else
    {
    strSQL="select code,name from jc_jddw where code in( select code from JC_JDDW connect by prior CODE=SJ_CODE start with SJ_CODE='J01'";
    strSQL+=" MINUS select sj_code from JC_JDDW connect by prior CODE=SJ_CODE start with SJ_CODE='J01')";
    }
    DbOper dboper=new DbOper(strSQL);            dt=new DataTable();
    dt.Columns.Add("if_checked");
                dt.Columns.Add("dw_code");
    dt.Columns.Add("dw_name");
    dt.Columns.Add("chklist");
    dt.Columns.Add("if_nextsj");
    dt.Columns.Add("if_havesj");

    if (dboper.CurrTB.Rows.Count>0)
    {
    for(int i=0;i<dboper.CurrTB.Rows.Count;i++)
    {
    DataRow newdr=dt.NewRow();

    newdr["dw_code"]=dboper.CurrTB.Rows[i]["code"].ToString();
    newdr["dw_name"]=dboper.CurrTB.Rows[i]["name"].ToString();
                        newdr["if_nextsj"]=IfNextJy(strYear,dboper.CurrTB.Rows[i]["code"].ToString());
    newdr["if_havesj"]=IfHaveSj(strYear,dboper.CurrTB.Rows[i]["code"].ToString());
                        
    if(IfNextJy(strYear,dboper.CurrTB.Rows[i]["code"].ToString())=="Y")
    {
    newdr["if_checked"]="1";
    }
    else
    {
    newdr["if_checked"]="0";
    }
    dt.Rows.Add(newdr); 

    }
    Session["table"]=dt;
    DataGrid1.DataSource=dt;
    // this.DataGrid1.CurrentPageIndex=0;
    DataGrid1.DataBind(); int istartrow=0;
             
    if (this.DataGrid1.PageCount==0)
    {
    return;
    }
    if (this.DataGrid1.PageCount==1)
    {
    istartrow=0;
    }
    if (this.DataGrid1.PageCount>1)
    {
    istartrow=this.DataGrid1.PageSize*this.DataGrid1.CurrentPageIndex;
    } System.Web.UI.WebControls.Label lb1;
    System.Web.UI.WebControls.Label lb2;
    System.Web.UI.WebControls.Image im1;
    System.Web.UI.WebControls.Image im2;
                System.Web.UI.WebControls.CheckBox chkbox; for (int i=0;i<DataGrid1.Items.Count;i++)
    {
    im1=(System.Web.UI.WebControls.Image)DataGrid1.Items[i].Cells[2].FindControl("img1");
    lb1=(System.Web.UI.WebControls.Label)DataGrid1.Items[i].Cells[2].FindControl("lb1");
    im2=(System.Web.UI.WebControls.Image)DataGrid1.Items[i].Cells[3].FindControl("img2");
    lb2=(System.Web.UI.WebControls.Label)DataGrid1.Items[i].Cells[3].FindControl("lb2");
                    chkbox=(System.Web.UI.WebControls.CheckBox)DataGrid1.Items[i].Cells[0].FindControl("chkbox"); if (dt.Rows[i+istartrow]["if_nextsj"].ToString()=="Y")
    {
    lb1.Width=0;
    im1.ImageUrl="../../images/Ok.bmp";
    chkbox.Visible=true;
    chkbox.Checked=false;
    chkbox.Width=10; }
    if (dt.Rows[i+istartrow]["if_nextsj"].ToString()=="N")
    {
    lb1.Text="无";
    im1.ImageUrl="../../images/blank.bmp";
    im1.Width=0;
    chkbox.Visible=false;
    } if (dt.Rows[i+istartrow]["if_havesj"].ToString()=="Y")
    {
    lb2.Width=0;
    im2.ImageUrl="../../images/Ok.bmp";
    }
    if (dt.Rows[i+istartrow]["if_havesj"].ToString()=="N")
    {
    lb2.Text="未形成";
    im2.ImageUrl="../../images/blank.bmp";
    im2.Width=0;
    }
    }
    }
      

  6.   

    to kaifagaoshou5:[email protected]@21cn.com两个都发吧~~
      

  7.   

    以上代码解释:
    在DataTable中增加一个if_checked列,BOOL型的,用来保存是否点击了,在翻页时候,根据这个值来确定DATAGRID的状态.
      

  8.   

    有一个家伙做了个VB.net的例子~~卡就卡在数组那了~~定义的数组在应用的时候有问题。
      

  9.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=F43AF9A5-2C2E-4AA6-E976-21E9569F5A8A
      

  10.   

    to    panzh10(阿潘)    
    刚test了一下~~不行!
      

  11.   

    to   babyjavalover(勇敢)
    那就跟我这个帖子一起,和高手学东西!
    to   xingbing(葡萄酒)
    不错的思路~~我试试~~最好有打包的源代码跑一次就更清楚了
    to   ym2000(tt) 
    哪呢?我刚看了,好像没有,挖出来给我发啊!
      

  12.   

    to  panzh10(阿潘)不好意思~~刚才test的有错~~实际可以用!谢谢大家1
    我忙完手头的工作来散分