Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed header column width in gridview?

Tags:

c#

asp.net

vb.net

I want to set header column width for grid view. I tried HeaderStyle-Width="30px". But it is depending on Item columns. The column width is setting based on item value. But I want fixed width even if it has value or empty.

alt text

like image 474
James123 Avatar asked Jun 19 '26 22:06

James123


1 Answers

You can also give Header style-Width and ItemStyle Width.It is also possible to add a span and set the width .So the item width will remains a value whether it is empty or contains any value.I think a little changes to the gridview will makes you to achieve a solution to your problem

<asp:TemplateField HeaderText="Category"  HeaderStyle-HorizontalAlign="Center"
                                    ItemStyle-HorizontalAlign="Center">
     <HeaderTemplate>
                                        <asp:LinkButton ID="lnkCategory" runat="server" ToolTip="Click here to sort by Category"
                                            CommandName="Sort" CommandArgument="Category" Text="Category" />
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                       <span style="width:50px"> <%#Eval("Category")%> </span>
                                    </ItemTemplate>
                                    <HeaderStyle HorizontalAlign="Left" Width="50px" ></HeaderStyle>
                                    <ItemStyle HorizontalAlign="Left" Width="50px"></ItemStyle>
                                </asp:TemplateField>

Nottable Changes are

<ItemTemplate>
     <span style="width:50px"> <%#Eval("Category")%> </span>
   </ItemTemplate>
  <HeaderStyle HorizontalAlign="Left" Width="50px" ></HeaderStyle>
   <ItemStyle HorizontalAlign="Left" Width="50px"></ItemStyle>
like image 119
kbvishnu Avatar answered Jun 22 '26 11:06

kbvishnu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!