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

[Solved] Dynamically set column width?

2 Answers 522 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul Taylor
Top achievements
Rank 1
Paul Taylor asked on 31 Mar 2009, 10:54 AM
Here's what I'm trying to do.

I am using a RadGrid to display some data and it is bound to a dataset so the columns are autogenerated but i want to set the column widths for each individual column.

I can set the width in headerStyle but it sets all the coumns to the same width but I have 2 columns that need to be very small (20 or 30 pixels) and a third column which contains some text which needs to take up about 70 or 80% of the table.

I have tried using the following code to access the columns, which should work as long as the columns exist

foreach (GridBoundColumn col in rGridNotes.MasterTableView.AutoGeneratedColumns)  
{  
    if (col.UniqueName == "Type")  
    {  
        col.HeaderStyle.Width = 20;  
    }  

but I am using this in the NeedDataSource even which isn't suitable as the rebind isn't called until after this even exits.

I have looked through the events available for RadGrid and can't see one that is suitable for executing this code after the RadGrid is populated with the columns. I need something like OnMasterTableCreated.

Any suggestions would be greatly appreciated.

2 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 31 Mar 2009, 02:10 PM
Hello Paul,

The event you can use to customize auto-generated column in RadGrid for ASP.NET AJAX is ColumnCreated. Further information on this subject can be found in these articles from the product documentation:

http://www.telerik.com/help/aspnet-ajax/grdusingcolumns.html
http://www.telerik.com/help/aspnet-ajax/grdgettingfamiliarwithserverapi.html

Best regards,
Sebastian
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Paul Taylor
Top achievements
Rank 1
answered on 31 Mar 2009, 08:52 PM
Hi Sebastian and thankyou for the prompt reply.

Exactly what I was looking for and worked a treat :-)

Paul
Tags
Grid
Asked by
Paul Taylor
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Paul Taylor
Top achievements
Rank 1
Share this question
or