Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 10-Feb-11 18:05pm
v2
Comments
Sunasara Imdadhusen 11-Feb-11 0:08am    
Where is code for Update value in Database, when i checked checkbox?
Albin Abel 11-Feb-11 1:50am    
Why the Item variable declared two times?
Dim item As GridDataItem = DirectCast(GD_APay.Items(0), GridDataItem)
For Each item In GD_APay.Items
you may declare the item in the foreach loop itself.

Also it is not good idea declare all those variable inside a loop. Declare outside the loop and assign value inside the loop
Monjurul Habib 11-Feb-11 3:28am    
create a javascript function that will capture only the checked id and pass that id to a update method. You should call the update method using javascript.

1 solution

give your checkbox command name

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900