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

[Solved] radgrid - set column width at runtime

1 Answer 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathibarani
Top achievements
Rank 1
Prathibarani asked on 16 Jul 2013, 09:07 PM
Hi,
  
We are using Radgrid and defining columns along with widths at design time like this:
  
<telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellSpacing="0" GridLines="None" GroupingEnabled="False" Height="215px" Width="99%" OnItemCommand=" RadGrid1_ItemCommand" OnItemDataBound="RadGrid1_ItemDataBound" OnPreRender="RadGrid1_PreRender" OnUnload="RadGrid1_Unload" OnBiffExporting="RadGrid1_BiffExporting">
            <ExportSettings ExportOnlyData="True" HideStructureColumns="True" OpenInNewWindow="True" FileName="TransactionSummary">
                <Excel Format="Biff" AutoFitImages="True" />
            </ExportSettings>
            <ClientSettings AllowExpandCollapse="False" AllowGroupExpandCollapse="False">
                <Selecting EnableDragToSelectRows="False" />
                <Scrolling AllowScroll="True" />
                <Resizing AllowColumnResize="True" ShowRowIndicatorColumn="False" />
            </ClientSettings>
            <MasterTableView DataKeyNames="TransactionID" AllowNaturalSort="false">
                <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>                 
                <Columns>
                    <telerik:GridBoundColumn AllowFiltering="False" DataField="TransactionID" Groupable="False" HeaderText="ID" ReadOnly="True" Reorderable="False" ShowFilterIcon="False" UniqueName="TransactionID" HeaderStyle-Width="5%" HeaderTooltip="Transaction ID Number" HeaderButtonType="None">
                        <HeaderStyle Width="5%" />
                        <ItemStyle HorizontalAlign="Left" Wrap="false" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn AllowFiltering="False" DataField="Status" Groupable="False" HeaderText="Status" ReadOnly="True" Reorderable="False" ShowFilterIcon="False" UniqueName="Status" HeaderStyle-Width="8%" HeaderTooltip="Status" HeaderButtonType="None">
                        <HeaderStyle Width="8%" />
                        <ItemStyle HorizontalAlign="Left" />
                    </telerik:GridBoundColumn>
  
My grid has around 13 columns, but only 10 are set to display true. Out of 3 (display – false), one column gets to be shown when user clicks on button to show it.
Some of the column’s display property is set to false. So, initially when grid is loaded which ever the columns are displayed, we made sure their total width comes to 99%. At run time based on some conditions, we are setting one of the column to be displayed. In order to display, we are adjusting the widths of columns by taking total visible columns like this:
  
double colPercentChange = (double)13 / colCnt;
  
 foreach (GridColumn col in pRgdTrans.Columns)
                    {
     if (col.Display == true)
     {
        double colWidthPercent = (double)col.HeaderStyle.Width.Value; // gridWidth;
        col.HeaderStyle.Width = Unit.Percentage(colWidthPercent - colPercentChange);
        col.ItemStyle.Width = Unit.Percentage(colWidthPercent - colPercentChange);
     }
  }
  
For all the columns it is working fine except TrnsactionID which is DataKey. The column width is getting doubled every time I click on button to make that column visible. All the columns are gridbound columns or template columns.
  
I appreciate your response.
Thanks,
Katta

1 Answer, 1 is accepted

Sort by
0
Venelin
Telerik team
answered on 19 Jul 2013, 03:01 PM
Hello Prathibarani,

I am afraid that the same issue is not replicating on my side. Here I attach a sample runnable project. Please examine it and let me know how it goes. If this doesn't help you please open a support ticket and give more clarifications on the scenario and if possible, attach a sample project that is isolating the issue.

I am looking forward to your reply.

Regards,
Venelin
Telerik
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 the blog feed now.
Tags
Grid
Asked by
Prathibarani
Top achievements
Rank 1
Answers by
Venelin
Telerik team
Share this question
or