Hi
I have a gridview with 3 columns. Say : id, Name and skill.
I want to know the column number of Column headers(May be Name,Skill or id)...
Thanks
Archan
![]() |
0 |
![]() |
I don't think there is any inbuilt way to do it. You have to loop through and compare the header text and get the index.
private int GetColumnIndex (string headerText) { int idx = 0; foreach (DataControlField gcf in GridView1.Columns) { if (gcf.HeaderText == headerText) { break; } idx++; } return idx; }
Mark replies as answers if they helped you solve the problem.
![]() |
0 |
![]() |
Hi siva
Thanks for your quick reponse.
Archan
![]() |
0 |
![]() |
This is another way u can do it. Hope this helps u. This is my first post.
private int getColumnIndex(string text)
{
for(int cnt=0;cnt<GridView1.Columns.Count;cnt++){
if (GridView1.Columns[cnt].HeaderText == text){
return cnt;break;}
}
return -1;}
![]() |
0 |
![]() |
Hi Anil
Thanks ...It is always helpful to know many ways to do the samething..
Archan
![]() |
0 |
![]() |