kdeutsch
asked on
Get cell value of gridview on command argument
Seems like I run into this everytime in a different situation trying to get gridview values and its a different syntax everytime. If anyone has a greate site that goes through all the different ways to get at the values please share. trying to get the values on a Row Command agrument,
I have text fields and a radio button that seems none of these work to get the values.
I have text fields and a radio button that seems none of these work to get the values.
If (e.CommandName = "Update") Then
Dim id As Integer = myGridview.DataKeys(e.CommandArgument).Value
'Dim data As TextBox = TryCast(myGridview.FindControl("txtData"), TextBox)
Dim data As String = myGridview.Rows(0).Cells(3).Text
Dim Remarks As String = myGridview.Rows(e.CommandArgument).Cells(4).Text
'Dim Remarks As TextBox = TryCast(myGridview.FindControl("txtRemarks"), TextBox)
Dim DtDate As String = myGridview.Rows(e.CommandArgument).Cells(5).Text
'Dim Dtdate As TextBox = TryCast(myGridview.FindControl("txtCal"), TextBox)
'Dim answer As RadioButtonList = TryCast(myGridview.FindControl("rblAll"), RadioButtonList)
sql = "Update tblSrpEventData set strData = '" & data & "', strRemarks = '" & Remarks & "', dtDoc = '" & DtDate & "', " _
& "dtlogged = '" & Date.Now & "' where intDataId = " & id
Response.Write(sql)
Response.End()
insertUpdateDelete(sql)
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
All,
I am simply trying to do an Update to a sql table when they click on a link button on the gridview it passes a commandname.
From here I want to get the values of the following cells
Rediobutton in cell 3
textbox in cell 4
textbox in cell 5
textbox in cell 6
Protected Sub myGridview_RowCommand(ByVa l sender As Object, ByVal e As System.Web.UI.WebControls. GridViewCo mmandEvent Args) Handles myGridview.RowCommand
If (e.CommandName = "Update") Then
Dim id As Integer = myGridview.DataKeys(e.Comm andArgumen t).Value
sql = "Update tblSrpEventData set strData = '" & data & "', strRemarks = '" & Remarks & "', dtDoc = '" & DtDate & "', " _
& "dtlogged = '" & Date.Now & "' where intDataId = " & id
Response.Write(sql)
Response.End()
insertUpdateDelete(sql)
End If
End Sub
I am simply trying to do an Update to a sql table when they click on a link button on the gridview it passes a commandname.
From here I want to get the values of the following cells
Rediobutton in cell 3
textbox in cell 4
textbox in cell 5
textbox in cell 6
Protected Sub myGridview_RowCommand(ByVa
If (e.CommandName = "Update") Then
Dim id As Integer = myGridview.DataKeys(e.Comm
sql = "Update tblSrpEventData set strData = '" & data & "', strRemarks = '" & Remarks & "', dtDoc = '" & DtDate & "', " _
& "dtlogged = '" & Date.Now & "' where intDataId = " & id
Response.Write(sql)
Response.End()
insertUpdateDelete(sql)
End If
End Sub
If you have given the CommandName as 'Update' then you have to handle the RowUpdating event for handling this. If the CommandName is 'Update' then it would not come to the RowCommand Event.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
All,
Ok I changed to the rowUpdating event and put the following into it, but I am getting no data when i do a respoonse.write.
Protected Sub myGridview_RowUpdating(ByV al sender As Object, ByVal e As System.Web.UI.WebControls. GridViewUp dateEventA rgs) Handles myGridview.RowUpdating
Dim UserLogon As String = Split(Current.User.Identit y.Name, "\")(1)
Dim Id As Integer = myGridview.DataKeys(e.RowI ndex).Valu e
Dim data As String = myGridview.Rows(e.RowIndex ).Cells(3) .Text
Dim Remarks As String = myGridview.Rows(e.RowIndex ).Cells(4) .Text
Dim DtDoc As String = myGridview.Rows(e.RowIndex ).Cells(5) .Text
Dim answer As RadioButtonList = myGridview.Rows(e.RowIndex ).FindCont rol("rblAl l")
sql = "Update tblSrpEventData set bitAnswer = " & answer.SelectedValue & ", strData = '" & data & "', strRemarks = '" & Remarks & "', dtDoc = '" & DtDoc & "', strLogged = '" & UserLogon & "', " _
& "dtlogged = '" & Date.Now & "' where intDataId = " & Id
Response.Write(sql)
Response.End()
insertUpdateDelete(sql)
End Sub
Ok I changed to the rowUpdating event and put the following into it, but I am getting no data when i do a respoonse.write.
Protected Sub myGridview_RowUpdating(ByV
Dim UserLogon As String = Split(Current.User.Identit
Dim Id As Integer = myGridview.DataKeys(e.RowI
Dim data As String = myGridview.Rows(e.RowIndex
Dim Remarks As String = myGridview.Rows(e.RowIndex
Dim DtDoc As String = myGridview.Rows(e.RowIndex
Dim answer As RadioButtonList = myGridview.Rows(e.RowIndex
sql = "Update tblSrpEventData set bitAnswer = " & answer.SelectedValue & ", strData = '" & data & "', strRemarks = '" & Remarks & "', dtDoc = '" & DtDoc & "', strLogged = '" & UserLogon & "', " _
& "dtlogged = '" & Date.Now & "' where intDataId = " & Id
Response.Write(sql)
Response.End()
insertUpdateDelete(sql)
End Sub
ASKER
Ok, finally got what I need by googling more on web about update row for gridview.
One simple way is to pass the rowIndex as the CommandArgument like:
CommandArgument='<%# Container.DataItemIndex %>'
Then you get the rowindex and its simple to get cell values like:
Dim index As Integer =Convert.ToInt32(e.Command
Dim id As Integer = myGridview.DataKeys(index).Value
Dim data As String = myGridview.Rows(index).Cells(3).Text