Solved

GridView - Get cell by name?

Posted on 2006-07-21
3
1,669 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 500 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

636 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