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

setting column width on render

4 Answers 162 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 24 Feb 2009, 04:43 PM
I am dynamically creating a datatable and a radgrid with autogenerated columns to display report information .
Some of the column headers are fairly long so I would like to increase the columns widths, I'm just not sure when the columns are generated. I tried changing them on ItemDataBound, it doesn't seem to recognize them.

            RadGrid gv = new RadGrid(); 
            gv.ID = "tmpGrid"
            gv.MasterTableView.HeaderStyle.VerticalAlign = VerticalAlign.Top; 
            gv.MasterTableView.HeaderStyle.Width = Unit.Pixel(200); 
            gv.ItemDataBound += new GridItemEventHandler(gv_ItemDataBound); 
            gv.AutoGenerateColumns = true
            gv.DataSource = master; 
            PlaceHolder1.Controls.Add(gv); 
            gv.DataBind(); 
 
        void gv_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem) 
            { 
                foreach (GridColumn gc in e.Item.OwnerTableView.RenderColumns) 
                { 
                    gc.HeaderStyle.Width = Unit.Pixel(200); 
                } 
            } 
        } 

Please help.
Aaron

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Feb 2009, 04:32 AM
Hi Aaron,

Try setting the width of the autoGeneratedColumns in the ColumnCreated event of the Grid.

CS:
 protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e) 
    { 
        if (e.Column.ColumnType == "GridBoundColumn"
        { 
            e.Column.HeaderStyle.Width = Unit.Pixel(100); 
        } 
    } 

Thanks
Shinu



0
Aaron
Top achievements
Rank 1
answered on 25 Feb 2009, 03:57 PM
Thanks Shinu,
I tried your solution and as I debug it hits that method when I add the grid to a placeholder on the page, but I still don't see a change.
Do you think it may be because I have a large number of columns in the grid?
Aaron
0
Princy
Top achievements
Rank 2
answered on 26 Feb 2009, 04:46 AM
Hello Aaron,

Try setting the TableLayOut property for the MasterTable to true as shown below and see if it helps:
aspx:
<telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="true" runat="server" OnColumnCreated="RadGrid1_ColumnCreated" > 
        <MasterTableView TableLayout="Fixed" > 
          .... 

Thanks
Princy.
0
Aaron
Top achievements
Rank 1
answered on 26 Feb 2009, 02:42 PM
That did it Princy. Problem solved.
Thanks a lot for your help!
Tags
Grid
Asked by
Aaron
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Aaron
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or