Gridview类Cell的属性未显示

问题描述 投票:0回答:1

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

Code :

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>");
}

Compile Time Error :

Watch this picture

Error :

See the Error

c# asp.net
1个回答
0
投票

你应该在下面的GridViewRow循环中使用GridView而不是foreach

foreach(GridViewRow row in GridView1.Rows)
{
.....
© www.soinside.com 2019 - 2024. All rights reserved.