Gridview Column Width in ASP.net
I'm looking to set the width of several columns to 0px initially and then controlling the width with jQuery when the table is rendered based on some user interaction on the front-end.
So far, I have
<asp:BoundField DataField="Col1" HeaderText="col1" >
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="0px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="0px />
</asp:BoundField>
but for some reason, the column is still showing. 开发者_开发百科Why? Its width is set at 0px??
Thanks.
I would use CSS to control width.
Inline:
<div style="width:0px;"></div>
Or defining a CSS class:
<div class="zero-width"></div>
But for what you're doing, I would go with the Visible
property.
<Columns>
<asp:BoundField DataField="Col1" HeaderText="col1" Visible="false">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundField>
<Columns>
But to assign a CSS class to your <asp:BoundField>
:
<Columns>
<asp:BoundField DataField="Col1" HeaderText="col1">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" CssClass="zero-width" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" CssClass="zero-width" />
</asp:BoundField>
<Columns>
精彩评论