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

RadGrid Set Column Width

6 Answers 1105 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 23 Nov 2010, 03:38 PM
I am trying to set the column width in the code behind and can not figure out how to do this.  My aspx looks like:


<
telerik:RadGrid ID="RadGrid1" AllowMultiRowSelection="True" runat="server" AutoGenerateColumns="False" GridLines="None" >

 

<

 

MasterTableView >

 

 

 

<Columns>

 

 

 

<telerik:GridBoundColumn DataField="INVOICE" UniqueName="INVOICE"

 

 

HeaderText="Invoice">

 

 

 

</telerik:GridBoundColumn>

 

 

 

<telerik:GridBoundColumn DataField="DATE" UniqueName="DATE" HeaderText="Date">

 

 

 

</telerik:GridBoundColumn>

 

 

 

<telerik:GridBoundColumn DataField="BOL" UniqueName="BOL" HeaderText="BOL">

 

 

 

</telerik:GridBoundColumn>

 

 

 

<telerik:GridBoundColumn DataField="PO" UniqueName="PO" HeaderText="PO">

 

 

 

</telerik:GridBoundColumn>

 

 

 

<telerik:GridBoundColumn DataField="POHIDE" UniqueName="POHIDE" Visible="false"

 

 

HeaderText="PO Hide" >

 

 

 

</telerik:GridBoundColumn>

 

 

 

</Columns>

 

</

 

MasterTableView>

 

 

 

<ClientSettings EnableRowHoverStyle="true" EnablePostBackOnRowClick="True" >

 

 

 

<Selecting AllowRowSelect="True" />

 

 

 

</ClientSettings>

 

 

 

</telerik:RadGrid>

I have tried using the RadGrid1_ColumnCreated event but no luck.  How do I change the column width at binding time?

Thanks

John

 

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Nov 2010, 06:38 AM
Hello John,

You can try the code in the RadGrid PreRender event. The following code snippet will help you to achieve your scenario.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
      GridColumn gridCol = RadGrid1.MasterTableView.GetColumn("LastName");
      gridCol.HeaderStyle.Width = Unit.Pixel(100);   
    }


Thanks,
Princy.
0
John
Top achievements
Rank 1
answered on 24 Nov 2010, 03:46 PM
Thank you very much
0
Dimo
Telerik team
answered on 24 Nov 2010, 05:03 PM
Hi John,

Please be aware that ColumnCreated is fired only for autogenerated columns.

All the best,
Dimo
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Sharada
Top achievements
Rank 1
answered on 07 Feb 2011, 02:47 PM
Thanx.

It worked nicely..

Darshan
0
Rajeev
Top achievements
Rank 1
answered on 06 Jul 2011, 09:27 PM
Post was helpful Thanks!
0
Frank
Top achievements
Rank 1
answered on 18 Aug 2015, 12:28 PM
Very late, but you want to use ((RadGrid)sender).MasterTableView.* instead. It will always apply to the correct RadGrid that way.
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
John
Top achievements
Rank 1
Dimo
Telerik team
Sharada
Top achievements
Rank 1
Rajeev
Top achievements
Rank 1
Frank
Top achievements
Rank 1
Share this question
or