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

Programmatically set colum width on RadGrid

5 Answers 1216 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 07 Oct 2011, 12:49 PM
I am trying to set the size of the columns on my radgrid to no avail. From reading the documentation and online the following should suffice but it makes no difference whatsoever:

 

 

GridColumn gridCol = radgrdResultDetail.MasterTableView.GetColumn("Description");
 gridCol.HeaderStyle.Width = System.Web.UI.WebControls.Unit.Pixel(500);

 

 

I have put this in the pre_render method like advised but the columns do not change size. Any help would be greatly appreciated.

Micahel

 

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Oct 2011, 04:54 AM
Hello Micheal,

Try the following code snippet to programmatically set column width on RadGrid columns.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    RadGrid1.MasterTableView.GetColumn("LastName").HeaderStyle.Width = Unit.Pixel(500);
}

Thanks,
Princy.
0
Michael
Top achievements
Rank 1
answered on 10 Oct 2011, 12:09 PM
Thanks you, that has woked to a certain degree. When i try to set a column width smaller than 80px it does not work, it stays at a larger width (this is not defined anywhere so i'm confused as to why it would do this). Is there a way i can explicity define the widths of each of my columns?
0
Pavlina
Telerik team
answered on 11 Oct 2011, 08:27 AM
Hello Michael,

I believe the following information will be useful for you:

http://www.telerik.com/community/forums/aspnet/grid/best-practice-for-grid-and-column-widths.aspx#1214355

All the best,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
thierry
Top achievements
Rank 1
answered on 10 Oct 2014, 03:33 PM
The link

http://www.telerik.com/community/forums/aspnet/grid/best-practice-for-grid-and-column-widths.aspx#1214355

is no longer valid.
0
Pavlina
Telerik team
answered on 13 Oct 2014, 10:30 PM
Hi,

Indeed the forum thread is no longer available, please excuse us for the inconvenience caused.

Regarding the issue with the column width - the most common reason for a column to appear a lot wider than expected is that you have set explicit pixel widths to all columns, but the RadGrid control is wider than the sum of all column widths. In this case you should leave at least one column with no width. Note that setting RadGrid column widths should be done only with HeaderStyle.Width

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Pavlina
Telerik team
thierry
Top achievements
Rank 1
Share this question
or