在复选框上更新网格数据 [英] update grid data on checkbox select

查看:51
本文介绍了在复选框上更新网格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有绑定列的网格和一个clientselectcolumn(复选框).
现在,当我选中任何复选框时,将使用存储过程在数据库中更新我的网格数据.工作正常.

问题是当我选中任何复选框时,它会更新所有行数据,而不仅是选中的行.

以下是VB代码:

I have one grid with bound columns and one clientselectcolumn(checkbox).
Now when I check any checkbox, my grid data is updated in database using a stored procedure. It was working fine.

The issue is when I check any of checkbox, it updates all rows data, and not just the checked ones.

Following is the VB code:

Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim item As GridDataItem = DirectCast(GD_APay.Items(0), GridDataItem)
        For Each item In GD_APay.Items
            Dim chkbx As CheckBox = DirectCast(item("chkcolumn").Controls(0), CheckBox)
            Dim str0 As String = item("School_number").Text.Trim
            Dim str1 As String = item("JOBR_VENDOR_NOUN").Text.Trim
            Dim str2 As String = item("Invoice_Date").Text.Trim
            Dim str3 As String = item("Invoice_Number").Text.Trim
            Dim str4 As String = item("OrderAmount").Text.Trim
            Dim str5 As String = item("Invoice_Amt").Text.Trim
            Dim str6 As String = item("ExceptionsFlag").Text.Trim
 Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("FConnectionString").ConnectionString)
            Dim cmd As New SqlCommand("P_FN_AP_SetInvoiceApprove", con)
            If (chkbx.Checked = True) Then
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@School_number", System.Data.SqlDbType.VarChar)
                cmd.Parameters("@School_number").Value = str0
                cmd.Parameters.Add("@JOBR_VENDOR_NOUN", System.Data.SqlDbType.VarChar)
                cmd.Parameters("@JOBR_VENDOR_NOUN").Value = str1
                cmd.Parameters.Add("@Invoice_Date", System.Data.SqlDbType.DateTime)
                cmd.Parameters("@Invoice_Date").Value = str2
                cmd.Parameters.Add("@Invoice_Number", System.Data.SqlDbType.VarChar)
                cmd.Parameters("@Invoice_Number").Value = str3
                cmd.Parameters.Add("@OrderAmount", System.Data.SqlDbType.Decimal)
                cmd.Parameters("@OrderAmount").Value = str4
                cmd.Parameters.Add("@Invoice_Amt", System.Data.SqlDbType.Decimal)
                cmd.Parameters("@Invoice_Amt").Value = str5
                cmd.Parameters.Add("@ExceptionsFlag", System.Data.SqlDbType.VarChar)
                cmd.Parameters("@ExceptionsFlag").Value = str6
                con.Open()
                cmd.ExecuteNonQuery()
                con.Close()
            End If
        Next
End Sub

推荐答案

提供您的复选框命令名称

并在gridview的rowcommand事件中
在您的命令名称下
你可以做任何你想做的事
give your checkbox command name

and in rowcommand event of gridview
under your command name
you can do whatever you want


这篇关于在复选框上更新网格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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