GridView - Get cell by name?

Posted on 2006-07-21
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:

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?
Question by:renesisx
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
LVL 24

Accepted Solution

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;
        return -1;
LVL 24

Expert Comment

ID: 17157374

Author Comment

ID: 17157490
That did the trick! Nice one :)

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity mvc , views, hidden values ? 2 26
Data organization issue 7 55 repeater 2 35
Difference between Highcharts and Mapbox 10 44
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 could not pull conte…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 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