【问题标题】:Set gridview's column width [duplicate]设置gridview的列宽[重复]
【发布时间】:2013-07-26 17:55:18
【问题描述】:

我的gridview如下:

但是当我在其中输入任何更大的文本时,其列增加如下:

在此我们可以看到,当我输入大文本英文问题栏时,已经生效。

我想保持修复。

为此,我在网格的模板字段中添加了<ItemStyle HorizontalAlign="Left" Width="45%" />

但它不起作用。我还为标签制作了wrap="true"。但对结果没有影响。

为了更清楚,我的整个网格代码如下:

  <asp:GridView ID="GrdQuestions" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                        CssClass="NormalText" PageSize="100" Width="100%">
                        <HeaderStyle CssClass="TableHeadingNormal TableAlt2" HorizontalAlign="Center" />
                        <RowStyle CssClass="AltColor21" />
                        <AlternatingRowStyle CssClass="AltColor22" />
                        <Columns>
                            <asp:TemplateField HeaderText="SrNo" HeaderStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Label ID="lblID" runat="server" Text='<%# Bind("SrNo") %>'></asp:Label>
                                    <asp:Label ID="lblQMID" runat="server" Text='<%# Bind("QMId") %>' Visible="false"></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle HorizontalAlign="Center" Width="3%" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="English Question">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtEnglish" runat="server" Text='<%# Bind("English") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblEnglish" runat="server" Text='<%# Bind("English") %>'></asp:Label>
                                    <%--
                                   <%# Eval("English") %>--%>
                                </ItemTemplate>
                                <HeaderStyle />
                                <ItemStyle HorizontalAlign="Left" Width="45%" Wrap="true" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Spanish Question">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtSpanish" runat="server" Text='<%# Bind("Spanish") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblSpanish" runat="server" Text='<%# Bind("Spanish") %>'></asp:Label>
                                    <%-- <%#Eval("Spanish")%>--%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Left" Width="45%" Wrap="true" />
                            </asp:TemplateField>
                            <asp:TemplateField ShowHeader="False" HeaderStyle-HorizontalAlign="Center">
                                <EditItemTemplate>
                                    <asp:LinkButton ID="LBUpdate" runat="server" CausesValidation="True" CommandName="Update"
                                        Text="Update"></asp:LinkButton>
                                    &nbsp;<asp:LinkButton ID="LBCancel" runat="server" CausesValidation="False" CommandName="Cancel"
                                        Text="Cancel"></asp:LinkButton>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:LinkButton ID="LBEdit" runat="server" CausesValidation="False" CommandName="Edit"
                                        Text="Edit"></asp:LinkButton>
                                    <asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False" CommandArgument='<%# Bind("SrNo") %>'
                                        CommandName="Delete" Text="Delete"></asp:LinkButton>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                                <HeaderStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

请帮帮我。

【问题讨论】:

  • @butterbox 我试过了,我已经在我的问题中提到过。
  • @butterbox 这给了我错误
  • 您是否尝试过使用文本块对其进行模板化并在文本块上设置 wrap 属性?
  • @Bearcat9425 我用标签 wrap="true" 完成了

标签: c# asp.net .net vb.net visual-studio-2008


【解决方案1】:

尝试将gridviewRowStyle-Wrap 属性设置为True。

【讨论】:

    猜你喜欢
    • 2020-11-28
    • 2017-09-13
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 2014-01-19
    • 2013-03-14
    • 2012-01-06
    • 2011-10-10
    相关资源
    最近更新 更多