Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对象引用未设置为对象的实例。运行此代码时出现以下错误此代码用于选中gridview复选框 受保护的无效按钮1\u单击(对象发送者,事件参数e) { 对于(int i=0;i_C#_Asp.net - Fatal编程技术网

C# 对象引用未设置为对象的实例。运行此代码时出现以下错误此代码用于选中gridview复选框 受保护的无效按钮1\u单击(对象发送者,事件参数e) { 对于(int i=0;i

C# 对象引用未设置为对象的实例。运行此代码时出现以下错误此代码用于选中gridview复选框 受保护的无效按钮1\u单击(对象发送者,事件参数e) { 对于(int i=0;i,c#,asp.net,C#,Asp.net,只需在使用复选框之前进行空检查即可 protected void Button1_Click(object sender, EventArgs e) { for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox ch = (CheckBox)GridView1.FindControl("chkid"); if (ch.Checked) {

只需在使用复选框之前进行空检查即可

protected void Button1_Click(object sender, EventArgs e)
{       
    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        CheckBox ch = (CheckBox)GridView1.FindControl("chkid");

        if (ch.Checked)
        {
            Response.Write("ch= true");
            Label1.Text = GridView1.Rows.ToString();
        }
        else
            Response.Write("ch= false");
    }                 
 }
受保护的无效按钮1\u单击(对象发送者,事件参数e)
{       
对于(int i=0;i
更正此行

protected void Button1_Click(object sender, EventArgs e)
{       
    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        CheckBox ch = (CheckBox)GridView1.FindControl("chkid");

        if (ch != null)
        {
            if (ch.Checked)
            {
                Response.Write("ch= true");
                Label1.Text = GridView1.Rows.ToString();
            }
            else
                Response.Write("ch= false");
        }
    }                 
 }

你能发布堆栈跟踪吗?
CheckBox ch = (CheckBox)GridView1.Rows[i].FindControl("chkid");