手动设置Gridview的列宽度



NET中,列的宽度由标题文本(或单元格中的内容)决定。在我的例子中,我有一个带复选框的列,我将列标题垂直放置,但列宽度根据标题文本而变化。所以我想做的是手动地有一个小列。我尝试了下面代码中所示的标准方法。

     <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代码编辑。

有谁能帮我一下吗?

添加"px"作为像素或"%"到宽度值怎么样?如:

ItemStyle-Width="10px" HeaderStyle-Width="10px"

我想这个计量单位是需要的

相关内容

  • 没有找到相关文章

最新更新