473,804 Members | 3,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to access column header text in Gridview

14 New Member
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.Tex tBox)GridView2. Rows[e.RowIndex].Cells[i].Controls[0]; //Cells[1].Controls[0];


cName.Text = GridView2.Colum ns[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 4928
Plater
7,872 Recognized Expert Expert
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
1600
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 format dd/mm but I need to store the full date (e.g. dd/mm/yyyy) in a hidden field for the column but only the last item in code is being rendered. Can you only add 1 item to a column? CODE---------------------------
3
3486
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 I can do with databinding. thanks Hans Merkl
3
3552
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 can get this to work; however, the column header on the datagrid is not a link/sortable. What am I missing? Thanks in advance.
4
6414
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 to look a and I am loosing tremendious amounts of time trying to organize it so that I could view it. Regards, Alexandre Brisebois
1
2426
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 other solution out there? Cheers Nick
5
4009
by: bbawa1 | last post by:
I have a GetData methd which is returning a table using
1
2138
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 i apply the Group box text font as Arial and bold this formatting applies to all controls which is placed inside the group box. But when i try to change the font as MsSanserif and Regular at ColumnheaderDefaultCell property of GridView,it will...
1
1692
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 i apply the Group box text font as Arial and bold this formatting applies to all controls which is placed inside the group box. But when i try to change the font as MsSanserif and Regular at ColumnheaderDefaultCell property of GridView,it will...
2
5406
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 GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) {
0
9585
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10586
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10323
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10082
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7622
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6856
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5658
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.