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

1/26/2006 3:22:33 PM 72751 articles. 3 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 26

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.



Mark as Answer, if this reply answers your post.
1/31/2006 10:27:18 PM

Hi, try to not use the e.Item.Cells(i).Text. If you make the DataGrid sortable, the header would be linkbutton, but not merely text. Therefore, locate the LinkButton in the If.....Else part and assign the text to it.

If e.Item.ItemType = ListItemType.Header Then 
      Dim lbtnHeader as LinkButton = CType(e.Item.Cells(i).Controls(0),LinkButton)
      lbtnHeader.Text = "whatever"
End If


I am not sure is it what you want. Tell me if not. :)


Alvin Chooi
Microsoft ASP.NET™ Enthusiast v1.1 / v2.0, Malaysia
Blog :
2/1/2006 1:24:13 AM

Similar Artilces:

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. ...

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! Penn i am surprised ...

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 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...

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...

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 - Changing Header Text on a Datagrid -

The Changing Light at Sandover - Wikipedia, the free encyclopedia
"The Changing Light at Sandover" is a 560-page epic poem by James Merrill (1926–1995). Sometimes described as a postmodern apocalyptic epic, ...

Is Facebook Changing How We Travel?
When one of your Facebook friends posts a photo album of their trip to Maui, they’re not just showing off — they might also be acting as a travel ...

Missed this week's Changing Track?... - 774 ABC Melbourne - Facebook
Missed this week's Changing Track? We've got you covered. Like to submit your own? Email it to

Facebook changing PMD program to Facebook Marketing Partners
Facebook’s Preferred Marketing Developer program may be getting a new look. Earlier today, Facebook announced on the Facebook for Business page ...

Changing Lanes (@chginglanes) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Changing the way business decisions are made
We believe that social data has unlimited value, and near limitless application. Today, we’re taking an important step toward unleashing this ...

12 Minutes To Create a Mind-Changing Presentation
... draft great presentations and to become a more effective and convincing presenter. Twelve minutes which can 12 Minutes To Create a Mind-Changing ...

We're Changing Our Name (Back) to Stack Overflow
We are Stack Overflow. You may know us from such popular websites as Stack Overflow Q&A, Stack Overflow Careers, The Stack Exchange Q&A Network, ...

The Tao of Twitter: Changing your life and business 140 characters at a time - Amazon
It's time to take the mystery out of Twitter. Twitter may be the most powerful business and personal networking platform ever created but it ...

App Store - Voices 2 ~ fun voice changing!
Read reviews, get customer ratings, see screenshots, and learn more about Voices 2 ~ fun voice changing! on the App Store. Download Voices 2 ...

Resources last updated: 12/6/2015 4:47:44 AM