Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

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
0
rflorencio
Asked:
rflorencio
  • 4
  • 4
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
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.  
0
 
rflorencioAuthor Commented:
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.GridViewCommandEventArgs) Handles GridView1.RowCommand

        If e.CommandName = "Add" Then
            Dim index As Integer = Convert.ToInt32(e.CommandArgument)
            Dim row As GridViewRow = GridView1.Rows(index)
            MsgBox(row.Cells("name").Text)
        End If

    End Sub


Error message:       
The conversion of the chain "name" to type 'Integer' is not valid.
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
it should just be row("name") . . .  not cells.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
rflorencioAuthor Commented:
in this case not work, is expected an integer as index
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
row('name") is for a datareader . . . sorry.

should be row.Item("Name")
0
 
rflorencioAuthor Commented:
when i try use your code, the help context show the following message:

'item' is not a member of System.Web.UI.WebControls.Gridviewrow
0
 
Kyle AbrahamsSenior .Net DeveloperCommented:
row needs to be a DataRow.  you may need to cast it using Ctype
0
 
rflorencioAuthor Commented:
how should do
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now