Solved

need to rename columns on datagrid...

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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