Reputation: 576
Can we set minwidth of any particular column of a gridview?
I am not using itemtemplate or databound.
Can we do it in C# or any other way?
Upvotes: 2
Views: 4063
Reputation: 3548
For auto-generated fields , you can use <asp:Label>
with Bind
,
<asp:TemplateField HeaderText="REQ_ID" SortExpression="REQ_ID" ItemStyle-CssClass="minWidth">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("REQ_ID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
its css
<style>
.minWidth {
min-width: 400px;
}
</style>
Upvotes: 0
Reputation: 35554
You have to use CSS for this. First set the ItemStyle-CssClass
to a specific class.
<asp:TemplateField ItemStyle-CssClass="minWidth">
<ItemTemplate>
<%# Eval("myColumn") %>
</ItemTemplate>
</asp:TemplateField>
Then define the minimum width for the column there
.minWidth {
min-width: 400px;
}
If you only use autogenerated columns you can do this
GridView1.HeaderRow.Cells[0].Attributes.Add("style", "min-width: 400px");
Upvotes: 3