postback后当然没有了,因为此时没有触发ItemDataBound

解决方案 »

  1.   

    ÔÚÄãµÄPageLoadÖÐдһ¸ö
    if(this.IsPostBack)
    {
    foreach(System.Web.UI.WebControls.DataGridItem e in this.dgList.Items)
    {
    System.Web.UI.WebControls.CheckBox objChk=new CheckBox();
    objChk.Text="";
    objChk.Visible =true;
    objChk.EnableViewState=true;
    e.Item.Cells[0].Controls.Add(objChk);
    if((e.Item.Cells[1].Text.Length>0)&&e.Item.Cells[0].Text!=" ")
    objChk.Checked =true;
    }
    }
      

  2.   

    老兄,先绑定一个模版列,里面放上CheckBox控件,给它一个ID.
    改变其状态的代码示范:
    int i;
    for( i=0;i < dg1.Items.Count;i++)
    {
         if(db.getrs("select code from b_unreturnpart where code='"+dg1.Items[i].Cells[2].Text+"'").Tables[0].DefaultView.Count>0)
         {
    CheckBox chk = (CheckBox)dg1.Items[i].FindControl("Select");
    chk.Checked=false;
          }
    }