Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.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 - Fatal编程技术网

C# 未从网格视图捕获复选框值

C# 未从网格视图捕获复选框值,c#,asp.net,C#,Asp.net,我正在尝试从GridView获取读取值并上传到数据库中 我能够读取文本值,但无法获取GridView复选框值 在asp.C中运行以下代码时,我在数据库表中只得到false(0)# 我在Button事件中的代码如下:- protected void btnSave_Click(object sender, EventArgs e) { btnSave.Visible = false; btnEdit.Visible = true; i

我正在尝试从GridView获取读取值并上传到数据库中

我能够读取文本值,但无法获取GridView复选框值

在asp.C中运行以下代码时,我在数据库表中只得到
false(0)
#

我在Button事件中的代码如下:-

    protected void btnSave_Click(object sender, EventArgs e)
    {
        btnSave.Visible = false;
        btnEdit.Visible = true;
        int i = 0;
        string defaultvalue = "0";
        foreach (GridViewRow row in grdExtApp.Rows)
        {
            string qry = "INSERT into tb_externalsystemaccess(User_Id,     SystemName,Access_status) VALUES (@v1, @v2, @v3)";
            SqlConnection con = new SqlConnection(str);
            using (SqlCommand cmd = new SqlCommand(qry, con))
            {
                cmd.Parameters.AddWithValue("@v1", TextBox3.Text);    
                cmd.Parameters.Add("@v2", SqlDbType.Text).Value = Convert.ToString    (row.Cells[0].Text);
                CheckBox chkBx = (CheckBox)row.FindControl("AccessExternal");
                if (chkBx.Checked)
                {
                    defaultvalue = "1";
                }
                cmd.Parameters.Add("@v3", SqlDbType.Bit).Value = Convert.ToInt16    (defaultvalue);
                con.Open();
                cmd.ExecuteNonQuery();
                i = i + 1;

            }
        }
    }
我从外部文本框控件获取v1值

v2值来自GridView单元格。它是一个字符串值,我可以捕获它

v3值是复选框值..它无法捕获..而仅显示为false,即使我选中了复选框

我的GridView标记如下所示:

     <asp:GridView ID="grdExtApp" runat="server" 
                AutoGenerateColumns="False" BackColor="White">
                          <Columns>
                          <asp:BoundField DataField="External_System"       HeaderText="External System" />  



                  <asp:TemplateField HeaderText="Access">  

                      <ItemTemplate>  

                          <asp:CheckBox ID="AccessExternal" runat="server"      Enabled="true" />  

                   </ItemTemplate>  

                 </asp:TemplateField>  


                          </Columns>

            </asp:GridView>

请帮助我为什么无法获取复选框值

protectedvoidbtnsave\u单击(对象发送者,事件参数e)
Protected void btnSave_Click(object sender, EventArgs e)
    {
        btnSave.Visible = false;
        btnEdit.Visible = true;
        //int i = 0;
        //string defaultvalue = "0";

         string qry = "INSERT into tb_externalsystemaccess(User_Id,SystemName,Access_status) VALUES (@v1, @v2, @v3)";
            SqlConnection con = new SqlConnection(str);
              for (int i = 0; i < grdExtApp.Rows.Count; i++)
            {

                GridViewRow row = grdExtApp.Rows[i];
                bool defaultvalue  = ((CheckBox)row.FindControl("AccessExternal")).Checked;
                cmd.Parameters.AddWithValue("@v1", TextBox3.Text);    
                cmd.Parameters.Add("@v2", SqlDbType.Text).Value = Convert.ToString(row.Cells[0].Text);
                cmd.Parameters.Add("@v3", SqlDbType.Bit).Value =defaultvalue;
                con.open();
                cmd.ExecuteNonQuery();
                con.Close();
                con.Dispose();

            }

    }
{ btnSave.Visible=false; btnEdit.Visible=true; //int i=0; //字符串defaultvalue=“0”; string qry=“插入tb_externalsystemaccess(用户Id、系统名称、访问状态)值(@v1、@v2、@v3)”; SqlConnection con=新的SqlConnection(str); 对于(int i=0;i
受保护的无效btnSave\u单击(对象发送方,事件参数e)
{
btnSave.Visible=false;
btnEdit.Visible=true;
//int i=0;
//字符串defaultvalue=“0”;
string qry=“插入tb_externalsystemaccess(用户Id、系统名称、访问状态)值(@v1、@v2、@v3)”;
SqlConnection con=新的SqlConnection(str);
对于(int i=0;i
受保护的无效btnSave\u单击(对象发送方,事件参数e)
{
btnSave.Visible=false;
btnEdit.Visible=true;
//int i=0;
//字符串defaultvalue=“0”;
string qry=“插入tb_externalsystemaccess(用户Id、系统名称、访问状态)值(@v1、@v2、@v3)”;
SqlConnection con=新的SqlConnection(str);
对于(int i=0;i
受保护的无效btnSave\u单击(对象发送方,事件参数e)
{
btnSave.Visible=false;
btnEdit.Visible=true;
//int i=0;
//字符串defaultvalue=“0”;
string qry=“插入tb_externalsystemaccess(用户Id、系统名称、访问状态)值(@v1、@v2、@v3)”;
SqlConnection con=新的SqlConnection(str);
对于(int i=0;i
btn\u Save()
是一种回发方法,我在您的
表单中假设加载()
您总是重新绑定网格,从而清除您的复选框

您应该将其放在
表单的顶部\u Load()

btn\u Save()
是一种回发方法,我在您的
表单\u Load()
中假设您总是重新绑定网格,从而清除复选框

您应该将其放在
表单的顶部\u Load()

btn\u Save()
是一种回发方法,我在您的
表单\u Load()
中假设您总是重新绑定网格,从而清除复选框

您应该将其放在
表单的顶部\u Load()

btn\u Save()
是一种回发方法,我在您的
表单\u Load()
中假设您总是重新绑定网格,从而清除复选框

您应该将其放在
表单的顶部\u Load()

if (!Page.IsPostBack)
    {
        grdExtApp.DataSourceID = "yourDatasourceID";
        grdExtApp.DataBind();
    }