Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.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# 检查C中的gridview中是否存在已批准复选框#_C#_Asp.net_Checkbox_Gridview - Fatal编程技术网

C# 检查C中的gridview中是否存在已批准复选框#

C# 检查C中的gridview中是否存在已批准复选框#,c#,asp.net,checkbox,gridview,C#,Asp.net,Checkbox,Gridview,我在gridview行中有一个复选框 我知道如何使用RowDataBound禁用它,并使用数据库值作为禁用或不禁用的条件 protected void gvProducts_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.DataItem != null) {

我在gridview行中有一个复选框

我知道如何使用
RowDataBound
禁用它,并使用数据库值作为禁用或不禁用的条件

protected void gvProducts_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.DataItem != null)
        {
            int status = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "tstatus"));
            CheckBox chkRow = (CheckBox)e.Row.FindControl("chkRow");

            if (status > 0)
            {
                chkRow.Enabled = false;
                chkRow.Checked = true;
                chkRow.ToolTip = "Approved";
            }
        }
    }
}
我的问题是检查gridview中是否有“已批准”复选框

foreach (GridViewRow row in gvProducts.Rows)
{
    if (row.RowType == DataControlRowType.DataRow)
    {
        CheckBox chkRow = (CheckBox)(row.Cells[0].FindControl("chkRow"));

        if (chkRow.Checked && chkRow.ToolTip == "to be approved")
        {
            int oIndividualID = Convert.ToInt32((gvProducts.DataKeys[row.RowIndex].Value));

            using (MySqlConnection myConnectionString =
              new MySqlConnection(ConfigurationManager.ConnectionStrings["cn2"].ConnectionString))
            {
                using (MySqlCommand cmd =
                    new MySqlCommand(sql, myConnectionString))
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Connection.Open();
                    cmd.CommandText = "SP";
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("tid", oIndividualID.ToString());
                    cmd.ExecuteNonQuery();
                    cmd.Connection.Close();
                    Bindgrid();
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Approved');", true);
                }
            }
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('Not checkbox selected');", true);
        }
    }
}
在这种情况下,即当已经有一个选中复选框的网格行时,如果我尝试选择一个新复选框,则浏览器上的返回值为

“未选中复选框”

即使数据库表更新正确

这是页面标记

<asp:TemplateField HeaderText="Select">
    <ItemTemplate>
        <asp:CheckBox ID="chkRow" runat="server"
            ToolTip="to be approved" />
    </ItemTemplate>
</asp:TemplateField>


有人能帮忙吗?

请在标签中添加框架(看起来像ASP.NET):是WPF吗?WinForms?ASP.NET?@CorentPane好的,添加到标签ASP.NET请在标签中添加框架(看起来像ASP.NET):是WPF吗?WinForms?ASP.NET?@corentPane好的,添加到标记ASP.NET中