Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid Checkbox UPDATE Event Trigger w/ Double AutoPostBacks

Status
Not open for further replies.

eb24

Programmer
Dec 17, 2003
240
US
I have an .aspx page in which it displays 2 Datagrids on it. One towards the top and the other below separated by a button named Checkout. The top datagrid allows users to click on checkboxes so they can be 'transferred' to the bottom datagrid upon clicking on the button. I am having difficulty with my SQL UPDATE statement and was wondering if someone would be kind to assist me.

I am using John Kilgo's excellent article on Datagrid Checkboxes: Including a CheckBox Control Inside an ASP.NET DataGrid... for reference.

My code is as follows:

Sub btnCheckout_Click(sender As Object, e As ImageClickEventArgs)

Dim dgItem As DataGridItem
Dim chkSelected As CheckBox
Dim Selection As String
Dim strThisName As String
Dim strThisID As String

Dim objConn As SqlConnection
Dim objCmd As SqlCommand
objConn = New SqlConnection(ConfigurationSettings.AppSettings("ThisConnection"))
Dim strSql As String

strSql = "UPDATE tblThisTable SET ...(my stuff)... WHERE ThisID = '" & CType(dgItem.FindControl("lblThisID"),Label).Text & "'"
lblSelected.Text = "The following items have been checked out by you: "

Try
objCmd = New SqlCommand(strSql, objConn)
objConn.Open
For Each dgItem In myDataGrid.Items
chkSelected = dgItem.FindControl("chkSelection")
If chkSelected.Checked Then
strThisName = CType(dgItem.FindControl("lblThisName"),Label).Text
strThisID = CType(dgItem.FindControl("lblThisID"),Label).Text
End If
Next

Catch
Finally
If objConn.State = ConnectionState.Open Then
objConn.Close()
objConn.Dispose()
End If

End Try
End Sub

Upon the database being updated, the would like the page to 'refresh/autopostback' to display the current state of the database, i.e. what the user has just done.

Anyone's assistance will be greatly appreciated.
 
Looks like you're missing
Code:
objCmd.ExecuteNonQuery() 
[code]
objConn.Open
objCmd = New SqlCommand(strSql, objConn)
objCmd.ExecuteNonQuery()
objCmd.ExecuteNonQuery()
 
Typo: objCmd.ExecuteNonQuery() - should be there only once, of course.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top