Gridview类的属性单元格未显示

时间:2018-03-01 17:21:19

标签: c# asp.net

为什么GridView Control“Cells”的属性不显示。 任何人都可以帮我解决这个问题吗?

代码:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    foreach(GridView row in GridView1.Rows)
    {
        int enrollment = Convert.ToInt32(row.Cells[0].Text);
        String student1 = row.Cells[1].Text;
        RadioButton rbt1 = (row.Cells[2].FindControl("Present") as RadioButton);
        RadioButton rbt2 = (row.Cells[2].FindControl("Absent") as RadioButton);
        String status;
        if(rbt1.Checked)
        {
            status = "Present";
        }
        else
        {
            status = "Absent";
        }
        String date = DateTime.Now.ToShortDateString();
        String division = txtDepartment.SelectedValue;
        String shift = txtShift.SelectedValue;
        String year = txtYear.SelectedValue;
        SaveAttendance(enrollment, student1, date, status, division, shift, year);
    }
    Response.Write("<script>alert('Attendance Saved SuccessFully !!')</script>");
}

编译时错误:

Watch this picture

错误:

See the Error

1 个答案:

答案 0 :(得分:0)

您应该在[bar:rab, foo:oof, baz:zab] 循环中使用GridViewRow代替GridView

foreach