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.
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"
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"
strThisID = CType(dgItem.FindControl("lblThisID"
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.