【问题标题】:GridView automatically re-sizing itselfGridView 自动调整大小
【发布时间】:2012-11-02 23:40:54
【问题描述】:

我在 asp 中有一个 GridView,它会不断调整自身的大小。我可以以某种方式修复 GridView 的大小,使其不这样做吗?尽管 GridView 中的数据长度相同或更小,但它会不断缩小自己

我的asp代码:

    <asp:GridView ID="Grid" runat="server" AllowPaging="True" PageSize="18" OnPageIndexChanging="Grid_PageIndexChanging"
            ForeColor="Black" GridLines="Both" Width="991px" Height="600px" RowStyle-HorizontalAlign="Center"
        BackColor="White" BorderColor="#999999" BorderWidth="1px" 
            AutoGenerateColumns="False" style="margin-left: 9px">
            <Columns>
                <asp:TemplateField HeaderText="RequestID">
                <ItemTemplate>
                <a target = "_blank" href="www.danx/default?request=<%# Eval("request")%>"><%# Eval("request")%></a>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Barcode">
                <ItemTemplate>
                <a target = "_blank" href="www.danx/default?barcode=<%# Eval("barcode")%>"><%# Eval("barcode")%></a>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="adrid" HeaderText="AdrID" SortExpression="AdrID" />
                <asp:BoundField DataField="name" HeaderText="Navn" SortExpression="Name" />
                <asp:BoundField DataField="street" HeaderText="Vej" SortExpression="Street" />
                <asp:BoundField DataField="houseno" HeaderText="Husnr" 
                    SortExpression="HouseNo" />
                <asp:BoundField DataField="postal" HeaderText="Postnr" 
                    SortExpression="Postal" />
                <asp:BoundField DataField="city" HeaderText="By" SortExpression="City" />
                <asp:BoundField DataField="country" HeaderText="Land" 
                    SortExpression="Country" />
                <asp:TemplateField HeaderText="Lokation">
                <ItemTemplate>
                <a target = "_blank" href="https://maps.google.dk/maps?q=<%# Eval("latitude")%>,<%# Eval("longitude")%>"><%# Eval("latitudetxt")%></a>
                </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="date" HeaderText="ReceivedDate" 
                    SortExpression="ReceivedDate" />

            </Columns>
            <FooterStyle BackColor="#CCCCCC" />

<RowStyle HorizontalAlign="Center"></RowStyle>

            <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#999999" ForeColor="Blue" HorizontalAlign="Center" />
            <HeaderStyle BackColor="DarkGray" Font-Bold="True" ForeColor="Black" />
            <AlternatingRowStyle BackColor="LightGray" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#808080" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>

你能帮帮我吗?

【问题讨论】:

标签: asp.net .net gridview


【解决方案1】:

由于您为 gridview 使用固定宽度 (991px),因此列会随着其内容的增大而缩小/调整。您可以做的一件事是为您不想调整大小的那些列提供固定宽度(以 % 或固定)。例如

<ItemTemplate>
<a target = "_blank" href="www.danx/default?request=<%# Eval("request")%>"><%# Eval("request")%></a>
</ItemTemplate>

您还可以增加 GridView 的大小以轻松容纳列,例如如果容器大于 991px,则将其设置为 100%

【讨论】:

    【解决方案2】:

    这可能是因为单元格中的数据太长而没有空格..你总是可以使用

    td{word-wrap:break-word;}
    

    或者确保你有空格。

    甚至使用列的样式,明确设置宽度

    <asp:TemplateField HeaderText="RequestID" HeaderStyle-CssClass="setWidthClass">
                    <ItemTemplate>...
    

    甚至

     <asp:TemplateField HeaderText="RequestID" ItemStyle-Width="100">
    

    当然这可能与此无关。

    【讨论】:

    • 我在哪里使用td{word-wrap:break-word;} ??
    • 在你的样式表中,或者在你页面头部的
    • 我收到一条错误消息,指出自动换行不是已知的 CSS 属性名称
    • 它是大多数现代浏览器都支持的 css3,但请看这里:w3schools.com/cssref/css3_pr_word-wrap.asp
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 2018-02-06
    相关资源
    最近更新 更多