Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GridView - Get cell by name?

Posted on 2006-07-21
3
Medium Priority
?
1,670 Views
Last Modified: 2008-01-09
In my GridView I have a column, example:
<asp:hyperlinkfield headertext="Cheese" />

I've got a handler on the RowDataBound event.

Currently to access that cell I use:
e.Row.Cells(6)

I'm convinced there is some way using the framework to access that cell by something other than the Integer index, which is very messy.

I'd much rather iterate through somehow, find the cell based on the "headertext" property = "Cheese"

Can it be done?
0
Comment
Question by:renesisx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
Justin_W earned 2000 total points
ID: 17157368
You can use the following method to retrieve the column index of a GridView column by name:

     int GetColumnIndex(GridView grid, string colName)
    {
        int intCount = 0;
        foreach (DataColumn col in grid.Columns)
        {
            if (col.ColumnName.ToLower().Trim() == colName.ToLower().Trim())
            {
                return intCount;
            }
            intCount++;
        }
        return -1;
    }
0
 
LVL 24

Expert Comment

by:Justin_W
ID: 17157374
E.g.:
    e.Row.Cells(GetColumnIndex("Cheese"))
0
 
LVL 1

Author Comment

by:renesisx
ID: 17157490
That did the trick! Nice one :)
0

Featured Post

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!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

721 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