【问题标题】:GridView does not contain a definition for Cells?GridView 不包含 Cells 的定义?
【发布时间】:2019-02-02 01:38:28
【问题描述】:

我正在尝试使用以下代码来检查至少一个复选框已被选中。如果选中了一个复选框,那么该行中的一个文本框就会有一些值。但是当我使用Cells时它给了我一个错误@

错误是 Gridview 不包含“Cells”的定义,并且找不到接受 GridView 类型的第一个参数的扩展方法“Cells”。

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

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

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    你应该使用 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;
             }
    
         }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多