Solved

need to rename columns on datagrid...

Posted on 2004-04-15
4
327 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 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