0

我有一个网格视图:

     <asp:GridView ID="ParentSelect" runat="server" AutoGenerateColumns="false" OnRowCommand="ParentSelect_RowCommand" OnRowCreated="ParentSelect_RowCreated" emptydatatext="Please Submit A Clip. C'mon dude." ShowHeaderWhenEmpty="true" HorizontalAlign="Center" Width="600" CssClass= "table table-striped table-bordered table-condense" OnDataBound="ParentSelect_DataBound" DataKeyNames="SubmissionID" RowStyle-Wrap="true">
    <HeaderStyle BorderColor="Black" />
    <Columns>
        <asp:BoundField DataField ="SubmissionID" />
        <asp:TemplateField HeaderText ="Vote" ItemStyle-HorizontalAlign="center" HeaderStyle-CssClass="DisplayCenterHeaderGrid">

            <ItemTemplate>
                <asp:Imagebutton ID="VoteUp" runat="server" ImageUrl="Content/glyphicons-202-upload.png" Width="20" ToolTip="Vote Up" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>
        " CommandName="VoteUp" OnCommand="VoteUp_Command" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField ="Title" HeaderText="Title" Visible="True" HeaderStyle-Width="30" HeaderStyle-CssClass="DisplayCenterHeaderGrid"/>
        <asp:BoundField DataField ="VideoUrl" HeaderText="Title" Visible="false" />
        <asp:BoundField DataField ="Description" HeaderText="Title" Visible="false" />             
        <asp:BoundField DataField ="GenreSelection" HeaderText="Genre" Visible="True" HeaderStyle-Width="30" ItemStyle-HorizontalAlign="center" HeaderStyle-HorizontalAlign="Center" HeaderStyle-CssClass="DisplayCenterHeaderGrid" />
    </Columns>
</asp:GridView>

我几乎尝试了所有可以想象的方法来设置特定的列宽,但都没有成功。请帮忙

4

2 回答 2

1

尝试ItemStyle-Width为您设置此属性BoundField

 <asp:BoundField DataField ="Title" HeaderText="Title" Visible="True" 
  HeaderStyle-Width="30" HeaderStyle-CssClass="DisplayCenterHeaderGrid"
  ItemStyle-Width="300px"/>
于 2015-01-05T13:21:50.230 回答
0

在设计视图中,单击 GridView 句柄。将 BoundField 转换为 TemplateField。编辑模板。在 ItemTemplate 中设置控件的宽度属性。

结果示例代码:

        <asp:TemplateField HeaderText="Comments" SortExpression="comments">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("comments") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("comments") %>' Width="400px"></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
于 2017-03-28T16:13:01.720 回答