无法在引导网格视图中设置特定的列宽
本文关键字:设置 视图 网格 | 更新日期: 2023-09-27 18:36:15
我有一个网格视图:
<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>
我几乎尝试了所有可以想象到的方式来设置特定的列宽,但都没有成功。请帮忙
尝试为您的
BoundField
设置此属性ItemStyle-Width
<asp:BoundField DataField ="Title" HeaderText="Title" Visible="True"
HeaderStyle-Width="30" HeaderStyle-CssClass="DisplayCenterHeaderGrid"
ItemStyle-Width="300px"/>
在设计视图中,单击网格视图控点。将边界字段转换为模板字段。 编辑模板。在项模板中设置控件的宽度属性。
生成的示例代码:
<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>