我想知道datagril里的复选框是否选中,下面的代码在1.1里有效,
2.0里应该怎么改进才能获得网页里是否选中呢?
foreach(DataGridItem item in ttt.Items)
        {
            CheckBox move = (CheckBox)item.FindControl("votecheck");
            if (move != null)
            {
                if (move.Checked == 3 > 2)
                {
                    qq.updatevote(Convert.ToInt32(ttt.DataKeys[item.ItemIndex].ToString()));
                    lba.Text = "投票成功,谢谢!!";
                }
            }
         }

解决方案 »

  1.   

    datagrid还是一样
    gridview:
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            CheckBox move = (CheckBox)e.Row.FindControl("votecheck");
        }
      

  2.   

    System.Web.UI.WebControls.CheckBox chk;
                string _BO_NO = year + month + day + Number;
                foreach (GridViewRow dr in GridView1.Rows)
             {
             chk  = (CheckBox)dr.FindControl("checkboxname");
                 if (chk.Checked)
                 {
                   
                     int QTY = Convert.ToInt32(dr.Cells[4].ToString());
                     string PRD_NO = dr.Cells[2].ToString();
                     string PRD_NAME = dr.Cells[3].ToString();
                     string BO_NO = _BO_NO;
                     string insertSQL = "insert into OP_Prdt_Borrow(BO_NO,Prdt_NO) vaules('" + BO_NO + "','" + PRD_NO + "')";
                     link.ExcuteDataBase(insertSQL);             }
    在      if (chk.Checked) 这里过不去! 
    $exception {"未将对象引用设置到对象的实例。"} System.Exception {System.NullReferenceException}
    这要怎么处理啊!
      

  3.   

    在我原来的         chk  = (CheckBox)dr.FindControl("checkboxname");后面加上  if (chk == null)
                     continue;就行了!
    System.Web.UI.WebControls.CheckBox chk;
               
                foreach (GridViewRow dr in GridView1.Rows)
             {
             chk  = (CheckBox)dr.FindControl("checkboxname");
                      
                 if (chk == null)
                     continue;
               else
    {               
                 if (chk.Checked)
    } 
    这样可以用,楼主!
      

  4.   

    我用 foreach (GridViewRow dr in GridView1.Rows)
     是可以用了
      

  5.   

    在Page_OnLoad里面数据绑定前加if(!IsPostBack)就好了。唉,已经回答了4次了,有点像骗分的感觉-_-!
      

  6.   

    谢谢各位帮忙
    问题已解决
    愿来连数用dataset才行
    神奇