Solved

asp.net vb.net gridview name cells

Posted on 2009-03-31
8
346 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 39

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 39

Expert Comment

by:Kyle Abrahams
ID: 24029872
it should just be row("name") . . .  not cells.
0
 

Author Comment

by:rflorencio
ID: 24038232
in this case not work, is expected an integer as index
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 39

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 39

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now