Solved

asp.net vb.net gridview name cells

Posted on 2009-03-31
8
348 Views
Last Modified: 2012-05-06
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
Comment
Question by:rflorencio
  • 4
  • 4
8 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 24029531
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
 

Author Comment

by:rflorencio
ID: 24029828
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
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 24029872
it should just be row("name") . . .  not cells.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:rflorencio
ID: 24038232
in this case not work, is expected an integer as index
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 24043788
row('name") is for a datareader . . . sorry.

should be row.Item("Name")
0
 

Author Comment

by:rflorencio
ID: 24060497
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
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 24077334
row needs to be a DataRow.  you may need to cast it using Ctype
0
 

Author Comment

by:rflorencio
ID: 24094961
how should do
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Save ms data to server side. 19 55
asp Google Map 2 23
How to use NFS (Network File System) in Asp.net mvc 5? 4 43
Why use this lambda? 12 28
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question