如何使用csharp在asp.net中编写复选框uisng gridview的更新代码 [英] how to write the update code for checkbox uisng gridview in asp.net with csharp

查看:54
本文介绍了如何使用csharp在asp.net中编写复选框uisng gridview的更新代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

激活数据类型位使用



源代码如下;





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>





如下;

for将复选框值更新到数据库。





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() + "'";







来自以上代码如何在上面的代码中编写复选框更新。以及要在数据库中更新的复选框值。

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




from the above code how to write the checkbox update in the above code. and that checkbox value to be updated in the database.
how to write the code in asp.net using csharp.

推荐答案

关于这是不好的。你不应该像这样串起mash SQL,我可以通过访问这个表单来清除你的数据库。阅读SQL注入攻击。至于你的问题,我相信你需要在回发时搜索有问题的控件行以获得它的检查状态。总的来说,我建议使用AJAX而不是回发机制。
EVerything about this is bad. You should not string mash SQL like this, I can erase your database by accessing this form. Read up on SQL injection attacks. As for your question, I believe you need, on postback, to search the row in question for the control in question to get it''s check state. Overall, I recommend using AJAX instead of the postback mechanism.


这篇关于如何使用csharp在asp.net中编写复选框uisng gridview的更新代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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