2016-09-30 104 views
0

我想使用下面的代码来检查至少一个复选框已被选中。如果选中了一个复选框,该行中的文本框就会有一些值。但是,当我使用CellsGridView不包含单元格的定义?

该错误的GridView不包含的“细胞”,并没有扩展方法的“细胞”接受型的GridView的第一个参数的定义可以发现给我的错误。

我不知道为什么它给了我这个错误。

private Boolean checkIfChecked() 
    { 
     int check = 0; 

     foreach (GridView row in gvPizzaOrder.Rows) 
     { 
      CheckBox chk = row.Cells[0].Controls[1] as CheckBox; 
      if (chk.Checked) 
      { 
       check++; 
       TextBox quantity = row.Cells[3].Text as TextBox; 
       if (quantity.Text == "") 
       { 
        return false; 
       } 

      } 
     }//end forreach 

     if (check == 0) 
     { 
      return false; 
     } 
     else 
      return true; 
    }//end checkIfChecked 

回答

0

你应该用GridViewRow,因此您的代码将是:

foreach (GridViewRow row in gvPizzaOrder.Rows) 
{ 
    CheckBox chk = row.Cells[0].Controls[1] as CheckBox; 
    if (chk.Checked) 
    { 
     check++; 
     TextBox quantity = row.Cells[3].Text as TextBox; 
     if (quantity.Text == "") 
     { 
      return false; 
     } 

    } 
} 
相关问题