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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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#_Asp.net_Gridview - Fatal编程技术网

C# 尝试选中复选框,但在“如果”条件下,它似乎未被选中

C# 尝试选中复选框,但在“如果”条件下,它似乎未被选中,c#,asp.net,gridview,C#,Asp.net,Gridview,我想检查我将更新的行,但当我达到if条件时,如果没有检查,它就会出现 <asp:TemplateField HeaderText="Stock" ItemStyle-Width="72px" HeaderStyle-Width="72px"> <ItemTemplate> <asp:CheckBox ID="InStockCbx" runat="server" /> </

我想检查我将更新的行,但当我达到if条件时,如果没有检查,它就会出现

 <asp:TemplateField HeaderText="Stock" ItemStyle-Width="72px" HeaderStyle-Width="72px">
            <ItemTemplate>
                 <asp:CheckBox ID="InStockCbx" runat="server" />
            </ItemTemplate>
 </asp:TemplateField> 



    protected void UsedForButton_Click(object sender, EventArgs e)
    {

        foreach (GridViewRow row in GridView1.Rows)
        {
            CheckBox chkBox = row.FindControl("InStockCbx") as CheckBox;

            if (chkBox.Checked)
            {

                int id = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value.ToString());


                conn.Open();
                SqlCommand comm = new SqlCommand("UPDATE WorkTable SET InStock = 0, UsedOrder = @UsedOrder WHERE Id=@ID", conn);
                comm.CommandType = CommandType.Text;
                comm.Parameters.Add("@ID", SqlDbType.Int, 1).Value = id;
                comm.Parameters.Add("@UsedOrder", SqlDbType.VarChar).Value = UsedForTextBox.Text;
                comm.ExecuteNonQuery();
                conn.Close();

按钮单击时使用的受保护无效(对象发送方,事件参数e)
{
foreach(GridView1.Rows中的GridViewRow行)
{
复选框chkBox=row.FindControl(“InStockCbx”)作为复选框;
如果(chkBox.Checked)
{
int id=Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value.ToString());
conn.Open();
SqlCommand comm=new SqlCommand(“更新工作台集合InStock=0,UsedOrder=@UsedOrder,其中Id=@Id”,conn”);
comm.CommandType=CommandType.Text;
comm.Parameters.Add(“@ID”,SqlDbType.Int,1).Value=ID;
comm.Parameters.Add(“@UsedOrder”,SqlDbType.VarChar).Value=UsedForTextBox.Text;
comm.ExecuteNonQuery();
康涅狄格州关闭();

您是否将GridView的数据绑定包装在
IsPostBack
检查中?
如果(!IsPostBack){//bind grid}
没有,则解决了我的问题。非常感谢!