Solved

asp.net vb.net gridview name cells

Posted on 2009-03-31
8
349 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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
Please explain purpose of GZIP 4 58
ASP.NET MVC - Views 3 40
VB.net -  GroupBox / Panel DataBinding and behavior 3 23
How can I add google maps in vb.net. 2 18
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …

749 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