Solved

need to rename columns on datagrid...

Posted on 2004-04-15
4
323 Views
Last Modified: 2008-03-17
I'm pulling a bunch of columns from a datareader into a datagrid.  Right now it is handling all the formatting.

I just want to rename the column headers and leave everything else alone.  What is the simplest way to do this?

Thanks,

gridREQ.DataSource = rdr
gridREQ.DataBind()
0
Comment
Question by:Weller0123
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
iboutchkine earned 500 total points
Comment Utility
If you have added a tablestyle to your grid, you can use the HeaderText
property of the columnstyle to change the column heading.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
         'change header for col 2
         Dim dgcs As DataGridColumnStyle =
Me.dataGrid1.TableStyles(0).GridColumnStyles(2)
         dgcs.HeaderText = "newtitle"
         Me.dataGrid1.Refresh()
End Sub

====================================
without tablestyles you can change the col name in the datatable and rebind the grid

ds.Tables.Item(0).Columns(1).ColumnName = "Test Caption"
 
0
 

Author Comment

by:Weller0123
Comment Utility
Thanks...
0
 

Expert Comment

by:wmorales
Comment Utility
On your query when you call your field:

SELECT HeaderThat_I_DontWant AS HeaderThat_I_Want
FROM MyTable

...  or you can go iboutchkine way but it won't change the grid it will change the table(tablestyle)... what he said.
0
 

Expert Comment

by:wmorales
Comment Utility
Sorry I didn’t read iboutchkine last part that will change the grid as well... sorry.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now