Column width on Empty grid

2 posts, 0 answers
  1. Adam King
    Adam King avatar
    29 posts
    Member since:
    May 2010

    Posted 27 Jan 2014 Link to this post

    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"
                                            <MasterTableView DataSourceID="dsBFsDueToday" DataKeyNames="brfo_id">
                                                <AlternatingItemStyle CssClass="evenRowBFs" />
                                                    No BFs were found</NoRecordsTemplate>
                                                <HeaderStyle CssClass="HeaderBFs" />
                                                <ItemStyle CssClass="oddRowBFs" />
                                                    <telerik:GridTemplateColumn HeaderText="PID" DataType="System.Int32" UniqueName="prsn_id"
                                                        <ItemStyle HorizontalAlign="Left" Width="68px" VerticalAlign="Middle" />
                                                            <asp:Label runat="server" ID="lblPID" Text='<%# Eval("prsn_id") %>' CssClass="labelOneRowHighFontBigger"></asp:Label>
                                                    <telerik:GridTemplateColumn HeaderText="Name" DataType="System.String" UniqueName="Name"
                                                        <ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" Height="15px" Width="275px" />
                                                            <asp:Label runat="server" ID="lblName" Text='<%# Eval("Name") %>' CssClass="labelOneRowHighFontBigger"> </asp:Label>
                                            <ClientSettings EnablePostBackOnRowClick="True" EnableRowHoverStyle="True">
                                                <Scrolling AllowScroll="True"></Scrolling>
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 28 Jan 2014 in reply to Adam King Link to this post

    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.

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

Back to Top