Solved

need to rename columns on datagrid...

Posted on 2004-04-15
4
324 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
ID: 10835310
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
ID: 10835507
Thanks...
0
 

Expert Comment

by:wmorales
ID: 10835603
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
ID: 10835650
Sorry I didn’t read iboutchkine last part that will change the grid as well... sorry.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

18 Experts available now in Live!

Get 1:1 Help Now