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

Column width on Empty grid

1 Answer 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam King
Top achievements
Rank 1
Adam King asked on 27 Jan 2014, 05:15 PM
I'm wondering how to set a column width when my grid is empty.

Right now I'm using the <columns> to generate my template, and NoRecordsTemplate which just says 'No Rows'.
Inside Columns I have several GridTemplateColumn fields and use ItemStyle to set the width.
The problem is when the grid is empty the column widths do not apply.

I have pasted in the code for the grid below:

<telerik:RadGrid ID="rdGrdDueToday" Height="200px" runat="server" Width="100%" AutoGenerateColumns="False"
                                        Skin="Sunset" AllowCustomPaging="false" DataSourceID="dsBFsDueToday" AllowSorting="true"
                                        OnItemCommand="rdGrdGeneric_itemcommand" AllowPaging="false" DataKeyNames="brfo_id"
                                        OnDataBound="rdGrdGeneric_Databound">
                                        <MasterTableView DataSourceID="dsBFsDueToday" DataKeyNames="brfo_id">
                                            <AlternatingItemStyle CssClass="evenRowBFs" />
                                            <NoRecordsTemplate>
                                                No BFs were found</NoRecordsTemplate>
                                            <HeaderStyle CssClass="HeaderBFs" />
                                            <ItemStyle CssClass="oddRowBFs" />
                                            <Columns>
                                                <telerik:GridTemplateColumn HeaderText="PID" DataType="System.Int32" UniqueName="prsn_id"
                                                    SortExpression="prsn_id">
                                                    <ItemStyle HorizontalAlign="Left" Width="68px" VerticalAlign="Middle" />
                                                    <ItemTemplate>
                                                        <asp:Label runat="server" ID="lblPID" Text='<%# Eval("prsn_id") %>' CssClass="labelOneRowHighFontBigger"></asp:Label>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
                                                <telerik:GridTemplateColumn HeaderText="Name" DataType="System.String" UniqueName="Name"
                                                    SortExpression="Name">
                                                    <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Height="15px" Width="275px" />
                                                    <ItemTemplate>
                                                        <asp:Label runat="server" ID="lblName" Text='<%# Eval("Name") %>' CssClass="labelOneRowHighFontBigger"> </asp:Label>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>                                               
                                            </Columns>
                                        </MasterTableView>
                                        <ClientSettings EnablePostBackOnRowClick="True" EnableRowHoverStyle="True">
                                            <Scrolling AllowScroll="True"></Scrolling>
                                        </ClientSettings>
                                    </telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 Jan 2014, 09:41 AM
Hi Adam King,

It is not recommended to use ItemStyle-Width to set column widths. Only HeaderStyle-Width should be used. From your code I see that you have used only set ItemStyle-Width, please set it to HeaderStyle-Width and remove width property from ItemStyle-Width.

ASPX:
<telerik:GridTemplateColumn . . .>
  <HeaderStyle Width="68px" />
  <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" />
   <ItemTemplate>
   . . .
   </ItemTemplate>
</telerik:GridTemplateColumn>

Thanks,
Princy
Tags
Grid
Asked by
Adam King
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or