一个DataGrid控件,其中有一列是checkBox控件,该DataGrid带分页,在我选其他页的时候,如何保持前一页的checkBox的状态,用什么方法比较好,效率会比较高?

解决方案 »

  1.   

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

  2.   

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

  3.   

    1.使用runat="server",当做服务器控件使用。
    2.自已写程序保持它的状态,可存于hidden字段或viewstate中。
      

  4.   

    以下代码解释:
    在DataTable中增加一个if_checked列,BOOL型的,用来保存是否点击了,在翻页时候,根据这个值来确定DATAGRID的状态.
    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;
    }
    }
    }
      

  5.   

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

  6.   

    那个checkbox如果是runat=server的,是可以自动保存状态的。