I have pulled data from SQL Server into a GridView control.
Two of the columns are checkbox fields.
During run-time,I am to click those columns to enter a check.
But how can I find out if the values of those items during run-tim
I need to allow the user to indicate whether they approve or deny a request; and then, I shall be able to update the corresponding columns in the originating database table.
What must I do to solve this problem?
During run-time, I added these two columns to the already existing ones:
CODE
Dim myCol1 As New DataColumn("Approved")
Dim myCol2 As New DataColumn("Denied")
myCol1.DataType = System.Type.GetType("System.Boolean")
myCol2.DataType = System.Type.GetType("System.Boolean")
myDataSet.Tables(0).Columns.Add(myCol1...
myDataSet.Tables(0).Columns.Add(myCol2...
myDataSet.Tables(0).AcceptChanges()
I have code in myGridView_RowUpdating():
CODE
Try
'For Each column As GridViewRow In myGridView.Rows(myGridView.EditIndex)
' Access the CheckBox
'Dim cb As CheckBox = column.FindControl("Approved")
'Perhaps could also check to see if the index of the row equals myGridView.EditIndex
For Each row As GridViewRow In myGridView.Rows
' Access the CheckBox
Dim cb As CheckBox = row.FindControl("Approved")
If cb IsNot Nothing AndAlso cb.Checked Then
Console.WriteLine("Found")
'Here, I want to see if the Approved checkbox is checked.
End If
Next
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
This is the code that I placed in myGridView_RowCommand():
CODE
Static intCount As Integer
Dim intRowIndex As Integer
'If intCount = 0 Then
intRowIndex = CInt(e.CommandArgument.ToString())
'dim intColumnIndex as Integer = cint(Request.Form(["__EVENTARGUMENT"])
myGridView.EditIndex = intRowIndex 'Place this particular row of the GridView control in edit mode.
intCount += 1
'End If 'If intCount = 0
Dim intResponse As Integer
Dim strAnswered As String
If (e.CommandName.Equals("Edit")) Then
ElseIf (e.CommandName.Equals("Update")) Then
Console.WriteLine("Update")
' If myGridView.Rows(intRowIndex).Cells.Item("2").ToString And myGridView.Rows(intRowIndex).Cells.Item("2").Text Then
' End If
'intResponse = MsgBox("Are you sure that you want to approve this request?", MsgBoxStyle.YesNoCancel, "Confirmation Required")
ElseIf (e.CommandName.Equals("Cancel")) Then
Else
'Nada
End If 'If (e.CommandName.Equals("Edit"))
If intResponse = vbCancel Then
MsgBox("The record has not been changed.", MsgBoxStyle.OkOnly, "No Action Taken")
Exit Sub
End If
If intResponse = vbYes Then
'Retreive the value of the key
Dim strKey As String
'strKey = myGridView.DataKeys(intRowIndex).Values(0).ToString 'Oops! There has been nothing assigned to DataKeys.
'Note: myGridView.Rows(intRowIndex).Cells.Item(0).Text is "", since it is the column of DELETE buttons.
'This gives the contents of the first row, first column. It would have been Cells.Item(0), had it not been
' displaced by the row of EDIT buttons.
strKey = myGridView.Rows(intRowIndex).Cells.Item(1).Text
'Call the handling routine, with strKey as a parameter.
'SupervisorResponse(strKey)
End If 'If intResponse = vbYes