Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.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 OnCheckedChange事件中查找复选框列_C#_Asp.net_Gridview_Checkbox_Oncheckedchanged - Fatal编程技术网

C# 在gridview OnCheckedChange事件中查找复选框列

C# 在gridview OnCheckedChange事件中查找复选框列,c#,asp.net,gridview,checkbox,oncheckedchanged,C#,Asp.net,Gridview,Checkbox,Oncheckedchanged,我有几个gridview列,带有复选框控件,它有一个autopostback='true'来更新数据库 当我选中其中一个复选框时,整行都会更新,这让我很沮丧 我试图找到列的复选框控件,而不是整个gridview 我知道Mycheckbox.checked将始终为真,因为它查看“所有已检查的值”,但我只希望它查看指定的列 是否可以执行类似于Checkbox MyCheckbox=findcontrol(*MyColumn*) protected void myCheckBox_OnChecked

我有几个gridview列,带有
复选框控件
,它有一个
autopostback='true'
来更新数据库

当我选中其中一个复选框时,整行都会更新,这让我很沮丧

我试图找到列
复选框控件
,而不是整个gridview

我知道
Mycheckbox.checked
将始终为真,因为它查看“所有已检查的值”,但我只希望它查看指定的列

是否可以执行类似于
Checkbox MyCheckbox=findcontrol(*MyColumn*)

protected void myCheckBox_OnCheckedChange(object sender, EventArgs e)
{    
    CheckBox myCheckBox = (CheckBox)sender;
    GridViewRow row = (GridViewRow)myCheckBox.NamingContainer;
    bool status = myCheckBox.Checked;   
    string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
    using (SqlConnection con = new SqlConnection(CS))
    {
        SqlCommand cmd = new SqlCommand("sp_tblPlanningChecked", con);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@PlanningID", row.Cells[1].Text);
        cmd.Parameters.AddWithValue("@ThisWeekMinus2", myCheckBox.Checked);
        cmd.Parameters.AddWithValue("@ThisWeekMinus1", myCheckBox.Checked);
        cmd.Parameters.AddWithValue("@ThisWeek", myCheckBox.Checked);
        cmd.Parameters.AddWithValue("@ThisWeekPlus1", myCheckBox.Checked);
        cmd.Parameters.AddWithValue("@ThisWeekPlus2", myCheckBox.Checked);
        cmd.Parameters.AddWithValue("@ThisWeekMinus3", myCheckBox.Checked);
        cmd.Parameters.AddWithValue("@ThisWeekMinus4", myCheckBox.Checked);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }

}

你能试试下面的代码吗

foreach (GridViewRow grow in GridView1.Rows)
{
    CheckBox chkStat = grow.FindControl("chkStatus") as CheckBox;
    int index = grow.RowIndex;
    if (chkStat.Checked)
    {
        //Write some code if checkbox is checked
    }
    else
    {
        //Write some code if checkbox is not checked
    }
}

我已经看过你的问题好几次了,但我还是不明白你想做什么。因此,您有
column1
,并且想要获得所有
复选框
Checked==true
?这完全令人困惑。在你的图片中有7列,每列都有10个复选框。这是什么意思:
我想知道如何使用列的“findcontrol”,而不是使用myCheckBox作为唯一的复选框发送者
?那么你想找一个控件?请回答
,以保持简单。此外,您不想将每个comboBox
s发送方在其事件中用作已转换的
comboBox`事件,那么您还想使用什么?你的总目标是什么?好吧,让我们假设我们在
列中。现在您想获得第1列中所有选中的
复选框
<代码>是
或<代码>否
?但现在您讨论的是一个(在本例中实现了这一点)列。但这一列有很多复选框。那么,当不同的复选框中有选中/未选中的复选框时,您如何想象得到true/false呢?我稍微修改了代码,但这行代码是:CheckBox chkStat=grow.FindControl(“chkStatus”)作为CheckBox;这是我追求的主线。