473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to access column header text in Gridview

this is used when the Updating Row is fired


the first line works in grabbing the text from the textbox of the cell, but I cannot access the column header text, as it's telling me the columns do not exist.

cName = (System.Web.UI.WebControls.TextBox)GridView2.Rows[e.RowIndex].Cells[i].Controls[0]; //Cells[1].Controls[0];


cName.Text = GridView2.Columns[i].HeaderText. + "=" + cName;

ETA: my columns of data (the first 2 columns were added as an edit and delete column) are added automatically/dynamically, I believe this might be the issue.


thanks.
Mar 6 '08 #1
1 4781
Plater
7,872 Expert 4TB
GridViews have a special property called HeaderRow which is where you can get your column text from.

For example, I search through the HeaderRow to discover which index is the column I am looking for. You should be able to figure out how to get the column text from it:
Expand|Select|Wrap|Line Numbers
  1. int retdateidx = -1;
  2. if (gvOverdueSites.HeaderRow != null)
  3. {
  4.    for (int i = 0; i < gvOverdueSites.HeaderRow.Cells.Count; i++)
  5.    {
  6.       if (gvOverdueSites.HeaderRow.Cells[i].Text == "Return Date")
  7.       {
  8.          retdateidx = i;
  9.       }
  10.    }
  11. }
  12. if (retdateidx != -1)
  13. {//retdateidx is the column index for the column with the header "Return Date"
  14. }
  15.  
Mar 7 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mark Parter | last post by:
I'm adding a dynamic column to a gridview control at runtime but I'm encountering a problem whereby I can only add 1 item to the column header. The column header should show the date in the...
3
by: Hans Merkl | last post by:
Hi, I was wondering if it's possible to bind the header text of a GridView column to a method of an object I have. At the moment I am setting the header texts in Page_Load but I was wondering if...
3
by: TPhelps | last post by:
I have a sample of an unbound (autogeneratecolumns is true) sortable/pagable datagrid that works. I want to change one of the columns to a hyperlink. The examples I find use a bound column. I...
4
by: alexandre.brisebois | last post by:
Hi, I am using access 2003, I would like to know if there is an option to reorganize the tables in a maner that is readable, as we can do in sql sever 2000 or 2005. I have been given a database...
1
by: Nick | last post by:
hi all: the one of the column of gridview got multiple line data to be shown , so how do i deal with it? what i am thinking about is using template field instead of the boundfield. is that...
5
by: bbawa1 | last post by:
I have a GetData methd which is returning a table using
1
sujathaeeshan
by: sujathaeeshan | last post by:
Hi All, I am doing UI design(form design modifications) not programmatically. I am facing problem while appplying font to Data grid column . Here i am placing Data Grid within GroupBox. When...
1
sujathaeeshan
by: sujathaeeshan | last post by:
Hi All, I am doing UI design(form design modifications) not programmatically. I am facing problem while appplying font to Data grid column . Here i am placing Data Grid within GroupBox. When...
2
by: gnewsgroup | last post by:
I have a GridView, in which the header of one column changes depending on the selected value of a DropDownList outside of this GridView. I did this dynamic header through protected void...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.