Change datagrid header text

I have a datagrid and I need to programatically change each column's header text based on user's previous input.

I put the code in OnItemDataBound event like this:

 if (e.Item.ItemType == ListItemType.Header)


 for (int i = 0; i <= e.Item.Cells.Count - 1; i++)


e.Item.Cells[i].Text = "something";



The header text did get changed, but it changed it into static text which is not clickable so sorting cannot be performed. How do I change the header text but still make sorting enabled?

It's been bothering me for a while now ... thanks a lot!


4/19/2006 8:52:26 PM 72751 articles. 3 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 20

i am surprised it even changed for you.  I couldnt even get it to change at itemdatabound.  the only place i can change the headertext and have the sorting functionality still in tact is right before i bind the grid.  For instance:


dg.columns(0).headertext="Change me"


4/19/2006 9:37:58 PM

That does the trick! All i have to do is to move the code before DataBind is called.

Thanks a million!!!!


4/19/2006 9:52:10 PM

Similar Artilces:

Changing Header Text on a Datagrid
I have headers that post back to sort - I am attempting to change the text with each sort so as to indicate that is the current sort column and the sort direction howevere when I  do something like this it wipes out the link - can anyone please advise how to  thanks in advanve If e.Item.ItemType = ListItemType.Header Then e.Item.Cells(i).Text = "whatever" End If I've never had to do anything like that before, but i think you have to find the link in the header and change the text value. Do a google search, i'm sure something will pop up.  DarmarkMark as Answer, if ...

Changing the datagrid header text
Is this possible at all? I have an application that runs in different languages and I want to display the header in the current language (stored in the session). Thanks in advance Heki Yes, it is defenetely possible. You will have to use resource files to achieve that. Idea is - there will be one resource file to store the default string values and one resource file for each language you want to support. So, say i add two resource files to my project: MyForm.resx and first being the default resource and second containing versions of the strings in Russian. ...

Changing Header Text of Datagrid Programatically
I have a datagrid. It is bound to an object data source.  I want to change the header text in one of the columns each time the data changes – which is basically at every postback.   By way of background, I created template fields using the Fields dialog box.  I have listed a portion of the code from the datagrid I am working on below.  I want to programmatically change  the headertext “services”.  I have tried using  findcontrol but I keep getting a null exception.  Any ideas would be appreciated. Thanks   <asp:TemplateField HeaderText=&...

Datagrid column header text change
How to change the datagrid (MyDatagrid) column hedare text via load event without using itemdatabound event. Datagrid name: MyDatagrid column 2 text = OrderNo Thank you very much for the helpful info.     You can't! The Page.Load event is too early in the Page life cyce. You must wait until the ItemDataBound event or after.Thanks, EdMicrosoft MVP - ASP/ASP.NET Can you please tell me, how to change the header text of datagrid in the itemdatabound.   Thanks.   void DataGrid1_itemDataBound(object sender, DataGridItemEventArgs e)    { &nb...

Change Header Text in the DataGrid on Selection.
Hi,  I have a problem in inserting a combo box in to a Data grid Header which has an Img when click it has to display the Combobox for selection of the new column name.I created a control which has a Span, Select box and an Img when clicks on the Img, it shows the select box for column selection and displays the column name in the span innertext.But i am unable to use the same control for different columns as i used Div for hiding and displaying the combo box. Can you please give me an idea on how to improve these sort of controls, which i can use mulitple times on the same webpag...

Programmatically Change Datagrid Header Text
Hi, Can anyone please tell how to programmatically change the header text of a datagrid ? Thanks Phillip You have to change the header text in the ItemDatabound event. if(e.Item.ItemType = ListItemType.Header) { //If you have placed a label in the header.... Label lbl = e.Item.Controls[1] as Label; lbl.Text = "New header text"; } Also note that DataGridItem is derived from TableRow so you can do a lot of customizing.Mike Schellenberger - MCAD...

How to change the Header Text of a datagrid column dynamically?
Hi ,  Can any one guide me on how to change the header text of a datagrid column dunamically in code behind? i am using the follwing code in datagrid item databound, but its not working  if (e.Item.ItemType == ListItemType.Header) {  if (Session["RoleID"].ToString() == "6" | Session["RoleID"].ToString() == "13") { e.Item.Cells[5].Text = "Select Record"; }Pradeep My personal way of doing it is to define a custom header. Then I can grab an instance of a lable or literal control in this instance in the ItemdataBound ev...

Weekdays changing dynamically in Datagrid Column Header Texts
Dear All,I hav a prob.I hav a table t_custinfo containing customer ID,name and personal details.Now I hav a datagrid where in I hav to retrieve custID and custname in two columns.In other columns I need to display weekdays say Mon to Sun with dates..The weekdays hav to change dynamically.In the grid user enters the amount collected from the customers for ex:CustID Custname Mon-2/2/06 Tue-3/2/06 Wed-4/2/06....till Sun-..1      bharath   100          2000      1000   2  ...

changing text in static text control
Hello PB 11 build 8123 I have a window with a dwcontrol. When I am updating the dw control I want one of the column names (static text controls) to change based on a value I select in another column. So far I have the code in the itemchanged to capture the value of my selection in the field I first select. How do I take this value, (it can only be Y or N) and program one of the column headings (static text) to display a certain text? I can't seem to get it to work with setitem or settext. Those two funcs don't really work with column headings as far as I can see. A...

Changing the text of an input (text) control
Hi everyone, please answer the following: I have a html input control as follows  <input id="newSearch_keywords" type="text" class="text" value="<%=JobsSearchBusinessObject.CurrentKeywords %>" name="newSearch_keywords""/>    When the page loads I need to look at the text of this input field and remove any * chars that are in the text. Thanks for your help <input id="newSearch_keywords" type="text" class="text" value="<%=JobsSearchBusinessObject.CurrentKeywords.Re...

Changing column header text of a gridview inside user control
Hi,I have an ascx file with a gridview, and I need to change the header text of the gridview's column in the code-behind. Something like that:foreach (DataControlField col in GridView1.Columns){ col.HeaderText = GetString(col.HeaderText);}However, no matter where I place that code, the header texts return to their original value, and that's what's being displayed.What could be the reason for that? And how can it be solved?  ...Anyone? I'm having the feeling that I'm missing something quite basic here, any help would be very appreciated. Amit00: col.HeaderT...

text controls, when they change update the total control
I have 4 text field server controls formatted in currency like $1.00 like this one called Mastercard: <td width="130" style="WIDTH: 130px">Mastercard </td> <td width="21" style="WIDTH: 21px"><INPUT onkeypress="return(currencyFormatCents(this,',','.','$',event))" id="Mastercard" type="text" name="Mastercard" runat="server" style="WIDTH: 116px; HEIGHT: 22px" size="14"></td> When This control, or any of the other 4 I want to update a lab...

Change the text of a GridView header when not using a header template.
I am using a GridView with automatic column sorting.  I need to rename the column header based on the selection of a dropdown list.  I have figured out how to do this by changing the header to a template field and placing a hyperlink on the field.  But then I have to add a custom method to sort the field when the user clicks the hyperlink.  Plus the CSS formatting of the ASP.Net hyperlink field may be different than the the HTMLI would like to find the appropriate event to change it when binding.  I have found examples of how to change the row.Cells[#].Text...

text change, why wont you text change!!!!
Hi i've got a huge form with loadsa recordsets that populate text boxes, AND I MEAN LOADS!!!!It involves some calculationsI have text1.text which goes away and changes text2.text which is fine, but in text2.text i have another on text change thingy which it wont call :(any one have any ideas : )also does any one know how i could call a txt change, so it does the call total a. dont know if thats possible as well. Private Sub txtShare_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtShare.TextChanged Call Total_A() End SubThank you if any one one could help...

Web resources about - Change datagrid header text -

Want to preview our new DataGrid for Xamarin.Forms?
tl;dr Zumero.DataGrid is a Xamarin.Forms control for displaying data in rows and columns. If you would be interested in testing and previewing ...

Mad King DataGrid
This post is about scrolling in WPF and the egocentric DataGrid control. I’ll give the project background but if all you’re interested in is ...

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 295 ...

Microsoft Silverlight - Wikipedia, the free encyclopedia
Microsoft Silverlight is an application framework for writing and running rich Internet applications , with features and purposes similar to ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Casaba Security » Products » X5s Testing Tool For Finding XSS Vulnerabilities
Security analysis, consulting, development and testing partners who understand your business strategy.

CodeGuru - Microsoft developers related ideas, articles, tips, tricks, comments, downloads, and so much ...
CodeGuru is where developers can come to share ideas, articles, questions, answers, tips, tricks, comments, downloads, and so much more related ...

Caliburn Micro: WPF, Silverlight, WP7 and WinRT/Metro made easy.
A small, yet powerful framework designed for WPF, Silverlight and WP7. It implements a variety of UI patterns for solving real-world problems. ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 11 Jul 2012 11636: first draft of license proliferation committee report
FYI,the first draft report of the OSI's License Proliferation Committee.To join the OSI's license proliferation discuss email list, send anemail ...

Resources last updated: 12/24/2015 1:56:51 AM