I have a gridview with several columns each containing one button.
I can get the row id but not the column id or the button caption.
I made them all Select buttons which is the only way it will work on a hosted WEB site.
any other type of button and the GridView1_RowCommand dose not fire.
I just want 3 buttons and know which one I pressed?
DougP
I can get the row id but not the column id or the button caption.
I made them all Select buttons which is the only way it will work on a hosted WEB site.
any other type of button and the GridView1_RowCommand dose not fire.
I just want 3 buttons and know which one I pressed?
Code:
Private Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
Dim index As Integer
Dim selectedRow As GridViewRow
index = Convert.ToInt32(e.CommandArgument)
selectedRow = GridView1.Rows(index)
Me.lblName.Text = selectedRow.Cells(0).Text
' the following 6 lines are code I got from another WEB teh rem'ed out lines don't work
Dim currentCommand As String = e.CommandName
Dim currentRowIndex As Integer = Int32.Parse(e.CommandArgument.ToString())
'Dim ProductID As String = GridView1.DataKeys(index).Value 'this gives error
Label1.Text = "e.CommandName: " & currentCommand
Label2.Text = "e.CommandArgument.ToString: " & currentRowIndex.ToString
'Label3.Text = "GridView1.DataKeys(index).Value: " & ProductID
Dim cnn As SqlConnection
Dim cmd As New SqlCommand
cnn = New SqlConnection(gblconnectionString)
Try
cnn.Open()
With cmd
.Connection = cnn
.CommandText = "Attend"
.CommandType = CommandType.StoredProcedure
.Parameters.AddWithValue("Lastname", Me.lblName.Text)
.Parameters(0).SqlDbType = SqlDbType.Text
Debug.Print(e.CommandName)
Me.lblRowNumber.Text = e.CommandName.ToString
If e.CommandName.ToString = "Select" Then
.Parameters.AddWithValue("Present", "P")
.Parameters(1).SqlDbType = SqlDbType.Text
'ElseIf e.CommandName = "Absent" Then
' .Parameters.AddWithValue("Present", "A")
' .Parameters(1).SqlDbType = SqlDbType.Text
Else
.Parameters.AddWithValue("Present", "T")
.Parameters(1).SqlDbType = SqlDbType.Text
End If
.ExecuteNonQuery()
End With
Me.GridView1.DataBind()
Catch ex As Exception
MsgBox(Err.Number & " " & Err.Description)
End Try
DougP