This is a migrated thread and some comments may be shown as answers.

User-friendly column names please

2 Answers 40 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Clive Hoggar
Top achievements
Rank 1
Clive Hoggar asked on 23 Feb 2009, 09:10 PM
Hi

I have a RadGrid displaying 6 columns from an SQL DataSource. 'Autogenerate columns'
is checked.

All works fine except I almost never want to use column names from a database
for ordinary website visitors. They are condensed and unfriendly (The columns, that is,
not the website visitors!).

With the the standard Ajax toolkit the column headers could be specified separately, but
I don't see an easy way to do this with RadGrid.

Also I need to adjust column widths and justification( right/left/center)

How can I best do these things?

(VB for preference)

Thanks

Clive

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Feb 2009, 05:47 AM
Hello Clive,

I hope you want to display custom headertext for your autogenerated columns. If so, you can try accessing your columns using their UniqueNames(which will be same as the datafield of your database), and set the properties accordingly:
vb:
     Protected Sub RadGrid1_ColumnCreated(ByVal sender As Object, ByVal e As GridColumnCreatedEventArgs)  
         If e.Column.UniqueName = "Title" Then  
          ' customize the header text 
          e.Column.HeaderText = "CustomHeaderText" 
          ' set the width of the column 
          e.Column.HeaderStyle.Width = Unit.Pixel(200) 
          ' set the horizontal alignment for items  
          e.Column.ItemStyle.HorizontalAlign = HorizontalAlign.Right           
         End If  
     End Sub  

Thanks
Princy.
0
Clive Hoggar
Top achievements
Rank 1
answered on 24 Feb 2009, 04:59 PM
Thanks for this - it works fine!

I also used same approach to make the ID column invisible by adding

If e.Column.UniqueName = "ID" Then  
            e.Column.Visible = False 
End If 

Beginning to see the power of this component now...

I have a related question but I'll make a new post

thanks

Clive
Tags
Grid
Asked by
Clive Hoggar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Clive Hoggar
Top achievements
Rank 1
Share this question
or