对于网格视图如何使用复选框编写更新 [英] For Grid view How to write update for using check box

查看:68
本文介绍了对于网格视图如何使用复选框编写更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用复选框在网格视图中执行应用程序。



复选框的数据库字段如下;

激活数据类型位使用



源代码如下;





i am doing the application in grid view using check box.

Database field for checkbox is as follows;
Activate datatype bit is used

source code as follows;


<asp:TemplateField HeaderText ="select" HeaderStyle-HorizontalAlign ="left">
     <itemtemplate>
     <asp:CheckBox ID="chkdelete" runat = "server" ForeColor="black" />
     </itemtemplate>







在aspx.cs页面代码中如下;

用于更新数据库的复选框值。






in aspx.cs page code as follows;
for the update the checkbox value to the database.

 protected void ResultGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        TextBox txtFName = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtFName");
        TextBox txtLName = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtLName");
        TextBox txtCity = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCity");
        TextBox txtState = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtState");
        TextBox txtCountry = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCountry");
        TextBox txtDescription = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtDescription");

        SqlConnection conn = new SqlConnection("Server=(local);initial catalog=master;Trusted_Connection=True");
        cmd.Connection = conn;
        cmd.CommandText = "UPDATE Vendors SET VendorFName ='" + txtFName.Text + "',VendorLName ='" + txtLName.Text + "',VendorCity ='" + txtCity.Text + "',VendorState ='" + txtState.Text + "',VendorCountry ='" + txtCountry.Text + "',VendorDescription ='" + txtDescription.Text + "'  WHERE VendorId='" + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'";
        conn.Open();
        cmd.ExecuteNonQuery();
        ResultGridView.EditIndex = -1;
        FillVendorGrid();
        conn.Close();
    }

cmd.CommandText = "UPDATE Vendors SET VendorFName ='" + txtFName.Text + "',VendorLName ='" + txtLName.Text + "',VendorCity ='" + txtCity.Text + "',VendorState ='" + txtState.Text + "',VendorCountry ='" + txtCountry.Text + "',VendorDescription ='" + txtDescription.Text + "'  WHERE VendorId='" + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'";





来自上面的upda代码ting复选框如何编写代码。请帮助我如何编写复选框的代码。



如何使用csharp在asp.net中编写代码。



from the above code for updating check box how to write the code.please help me for how to write the code for check box.

how to write the code in asp.net using csharp.

推荐答案

获取CheckBox对象



CheckBox chkdelete =(CheckBox)ResultGridView.Rows [e.RowIndex ] .FindControl(chkdelete);



要传递Field Activate数据类型位的值,请使用此



,VendorDescription =''+ txtDescription.Text +'',Activate =''+ Convert.ToInt16(chkdelete.Checked)+''
To Get CheckBox Object

CheckBox chkdelete = (CheckBox)ResultGridView.Rows[e.RowIndex].FindControl("chkdelete");

To pass value for the Field Activate datatype bit use this

,VendorDescription =''" + txtDescription.Text + "'',Activate =''" +Convert.ToInt16(chkdelete.Checked) + "''


这篇关于对于网格视图如何使用复选框编写更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆