无法在 bootstrap gridview 中设置特定的列宽
Cannot set specific column widths in bootstrap gridview
我有一个网格视图:
<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"/>
在设计视图中,单击 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>
我有一个网格视图:
<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"/>
在设计视图中,单击 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>