rp
asked on
asp.net vb.net gridview name cells
It´s possible in the following example use the name of column instead the column number:
row.Cells(2).Text
for ex: like:
row.Cells("name").Text
row.Cells(2).Text
for ex: like:
row.Cells("name").Text
yes you can do this. In fact it's preferred because if you change your columns around programattically your indexes will all get messed up.
ASKER
But when i try with this code i get an error message in msgbox() line :
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls. GridViewCo mmandEvent Args) Handles GridView1.RowCommand
If e.CommandName = "Add" Then
Dim index As Integer = Convert.ToInt32(e.CommandA rgument)
Dim row As GridViewRow = GridView1.Rows(index)
MsgBox(row.Cells("name").T ext)
End If
End Sub
Error message:
The conversion of the chain "name" to type 'Integer' is not valid.
Protected Sub GridView1_RowCommand(ByVal
If e.CommandName = "Add" Then
Dim index As Integer = Convert.ToInt32(e.CommandA
Dim row As GridViewRow = GridView1.Rows(index)
MsgBox(row.Cells("name").T
End If
End Sub
Error message:
The conversion of the chain "name" to type 'Integer' is not valid.
it should just be row("name") . . . not cells.
ASKER
in this case not work, is expected an integer as index
row('name") is for a datareader . . . sorry.
should be row.Item("Name")
should be row.Item("Name")
ASKER
when i try use your code, the help context show the following message:
'item' is not a member of System.Web.UI.WebControls. Gridviewro w
'item' is not a member of System.Web.UI.WebControls.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
how should do