ASP .NET 2.0 GridView - how to locate column by name?

  • Thread starter Thread starter Erik
  • Start date Start date
E

Erik

Is there any way I can get index (position) of a column in an ASP .NET 2.0
GridView by referencing the column's name, either by using the DataField or
HeaderText properties? A small code snippet would be greatly appreciated!
I have tried with no luck so far.

Thanks!
 
Never fails, I figured it out today:

foreach (DataControlField col in GridView.Columns)
{
if (col.HeaderText == "column name")
{
int colPos = GridView.Columns.IndexOf(col)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top