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.

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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With