在ASP.NET的Gridview中,列的宽度由headertext(或单元格中的内容)决定。在我的情况下,我有一个带有复选框的列,我将列标题垂直放置,但列宽根据标题符号而变化。 所以我想手动做一个小列。我尝试了下面代码中显示的标准内容。
<asp:TemplateField AccessibleHeaderText="Geen" HeaderText="Geen trans" HeaderStyle-CssClass="VerticalHeader" ItemStyle-Width="10" ItemStyle-Wrap="false" HeaderStyle-Width="10" HeaderStyle-Wrap="false" HeaderStyle-HorizontalAlign="Left" >
<ItemTemplate>
<asp:CheckBox ID="cbNoTransport" runat="server" AutoPostBack="true" OnCheckedChanged="cbNoTransport_OnCheckedChanged"/>
</ItemTemplate>
</asp:TemplateField>
<div id="grid" style="overflow:scroll; overflow-Y:hidden;" >
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
DataKeyNames="Barcode" DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display." AllowPaging="True"
AllowSorting="True" onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdeleted="GridView1_RowDeleted" onrowediting="GridView1_RowEditing"
onrowupdated="GridView1_RowUpdated" onsorted="GridView1_Sorted"
onpageindexchanged="GridView1_PageIndexChanged" PageSize="30"
CssClass="Grid" onrowcommand="GridView1_RowCommand"
onrowdatabound="GridView1_RowDataBound" >
<Columns>
<asp:BoundField DataField="Barcode" HeaderText="Barcode"
SortExpression="Barcode">
</asp:BoundField>
<asp:BoundField DataField="Werkpakket" HeaderText="Werkpakket"
SortExpression="Werkpakket">
</asp:BoundField>
<asp:BoundField DataField="HA" HeaderText="HA" SortExpression="HA" />
<asp:BoundField DataField="Discipline" HeaderText="Discipline"
SortExpression="Discipline" >
</asp:BoundField>
<asp:BoundField DataField="Type" HeaderText="Type"
SortExpression="Type" >
</asp:BoundField>
<asp:BoundField DataField="Apparaat" HeaderText="Apparaat"
SortExpression="Apparaat" />
<asp:TemplateField AccessibleHeaderText="Geen" HeaderText="Geen trans" HeaderStyle-CssClass="VerticalHeader" ItemStyle-Width="1%" ItemStyle-Wrap="false" HeaderStyle-Width="1%" HeaderStyle-Wrap="false" HeaderStyle-HorizontalAlign="Left" >
<ItemTemplate>
<asp:CheckBox ID="cbNoTransport" runat="server" AutoPostBack="true" OnCheckedChanged="cbNoTransport_OnCheckedChanged"/>
</ItemTemplate>
<ItemStyle Width="5%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Lijn dienst" HeaderStyle-CssClass="VerticalHeader">
<ItemTemplate>
<asp:CheckBox ID="cbNoTransport" runat="server" AutoPostBack="true" OnCheckedChanged="cbNoTransport_OnCheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Intercity" HeaderStyle-CssClass="VerticalHeader">
<ItemTemplate>
<asp:CheckBox ID="cbNoTransport" runat="server" AutoPostBack="true" OnCheckedChanged="cbNoTransport_OnCheckedChanged"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Appendage" HeaderText="Appendage"
SortExpression="Appendage" />
<asp:BoundField DataField="Leiding" HeaderText="Leiding"
SortExpression="Leiding" />
<asp:BoundField DataField="user_added" HeaderText="user_added"
SortExpression="user_added" />
<asp:BoundField DataField="DTPrinted" HeaderText="DTPrinted"
SortExpression="DTPrinted" >
</asp:BoundField>
<asp:BoundField DataField="DTUpdated" HeaderText="DTUpdated"
SortExpression="DTUpdated" />
</Columns>
<HeaderStyle HorizontalAlign="Left" Wrap="False" />
<RowStyle HorizontalAlign="Left" Wrap="False" />
使用gridview代码编辑。
任何人都可以帮我吗?
答案 0 :(得分:0)
如何添加&#34; px&#34;像素或&#34;%&#34;到宽度量? 像:
ItemStyle-Width="10px" HeaderStyle-Width="10px"
我认为需要衡量单位。