thevan
thevan

Reputation: 10354

How to assign gridview column width automatically according to its value in asp.net?

I have one GridView which has multiple columns. Here I just mentioned only the two columns in the GridView.

<asp:TemplateField HeaderText="Tot. Qty." ItemStyle-Width="30px" ControlStyle-Width="30px" >
<ItemTemplate>
      <asp:Label ID="lblTotQty" runat="server" Text='<%# Bind("TotalQuantity") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="30px" />
<ControlStyle Width="30px" />
</asp:TemplateField>
<asp:BoundField DataField="UoM" HeaderText="UoM" ItemStyle-Width="25px" />

But the problem here is, when the Total Quantity column values is greater than 6 digits. then the value is displays continuously along with the next column value "UoM". How to increase the GridView column width of "Total Quantity" according to the Column's value?

Upvotes: 0

Views: 1445

Answers (1)

Pleun
Pleun

Reputation: 8920

Why don't you just NOT specify a width at all and let is size dynamically?

Alternative: calculate the width in code behind and set it there.

Upvotes: 1

Related Questions