簡體   English   中英

如何使我的gridview在頁面上適應100%

[英]how do i make my gridview to fit 100% on page

如何讓我的gridview在屏幕內很好地適應。 我添加了這個屬性width =“100%”i。 但是我的gridview仍然超出了我的標題寬度,我將其設置為100%。

在此輸入圖像描述

這是我第一次嘗試的gridview的源代碼。

<asp:GridView ID="GWCase" runat="server"  Top="0%" Width="100%" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" ForeColor="Black" Height="199px" AutoGenerateSelectButton="True" OnSelectedIndexChanged="GWCase_SelectedIndexChanged">

    <FooterStyle BackColor="#CCCCCC" />
    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
    <RowStyle BackColor="White" />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#808080" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>

我嘗試使用這樣的css方法

<ul id="assigngw">
<asp:GridView ID="GWCase" runat="server"  Top="0%" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" ForeColor="Black" Height="199px" AutoGenerateSelectButton="True" OnSelectedIndexChanged="GWCase_SelectedIndexChanged">

    <FooterStyle BackColor="#CCCCCC" />
    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
    <RowStyle BackColor="White" />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#808080" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
    </ul>

Css代碼:

#assigngw {
width:100%;
}

不幸的是兩者都不起作用。

這是我的完整源代碼。

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<link rel="stylesheet" href="css/style.css" type="text/css" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>

<ul id="assigngw">
    <asp:GridView ID="GWCase" runat="server" width="300px" Top="0%" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" ForeColor="Black" Height="199px" AutoGenerateSelectButton="True" OnSelectedIndexChanged="GWCase_SelectedIndexChanged">

    <FooterStyle BackColor="#CCCCCC" />
    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
    <RowStyle BackColor="White" />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <SortedAscendingCellStyle BackColor="#F1F1F1" />
    <SortedAscendingHeaderStyle BackColor="#808080" />
    <SortedDescendingCellStyle BackColor="#CAC9C9" />
    <SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
    </ul>


<br />
Case ID :
<asp:Label ID="lblCID" runat="server"></asp:Label>
&nbsp;is situation near
<asp:DropDownList ID="lblocation" runat="server" OnSelectedIndexChanged="lblocation_SelectedIndexChanged" AutoPostBack="True" DataTextField="location" DataValueField="location">
    <asp:ListItem>Select Location</asp:ListItem>
    <asp:ListItem>Bukit Batok NPC</asp:ListItem>
    <asp:ListItem>Bukit Panjang NPC</asp:ListItem>
    <asp:ListItem>Choa Chu Kang NPC</asp:ListItem>
    <asp:ListItem>Jurong West NPC</asp:ListItem>
    <asp:ListItem>Nanyang NPC</asp:ListItem>
    <asp:ListItem>Woodlands East NPC</asp:ListItem>
    <asp:ListItem>Woodlands West NPC</asp:ListItem>
    <asp:ListItem>Ang Mo Kio North NPC</asp:ListItem>
    <asp:ListItem>Ang Mo Kio South NPC</asp:ListItem>
    <asp:ListItem>Punggol NPC</asp:ListItem>
    <asp:ListItem>Hougang NPC</asp:ListItem>
    <asp:ListItem>Sembawang NPC</asp:ListItem>
    <asp:ListItem>Serangoon NPC</asp:ListItem>
    <asp:ListItem>Sengkang NPC</asp:ListItem>
    <asp:ListItem>Yishun North NPC</asp:ListItem>
    <asp:ListItem>Yishun South NPC</asp:ListItem>
    <asp:ListItem>Bedok North NPC</asp:ListItem>
    <asp:ListItem>Bedok South NPC</asp:ListItem>
    <asp:ListItem>Changi NPC</asp:ListItem>
    <asp:ListItem>Geylang NPC</asp:ListItem>
    <asp:ListItem>Marine Parade NPC</asp:ListItem>
    <asp:ListItem>Pasir Ris NPC</asp:ListItem>
    <asp:ListItem>Tampines NPC</asp:ListItem>
    <asp:ListItem>Bukit Merah West NPC</asp:ListItem>
    <asp:ListItem>Clementi NPC</asp:ListItem>
    <asp:ListItem>Queenstown NPC</asp:ListItem>
    <asp:ListItem>Jurong East NPC</asp:ListItem>
    <asp:ListItem>Bishan NPC</asp:ListItem>
    <asp:ListItem>Bukit Timah NPC</asp:ListItem>
    <asp:ListItem>Kampung Java NPC</asp:ListItem>
    <asp:ListItem>Orchard NPC</asp:ListItem>
    <asp:ListItem>Toa Payoh NPC</asp:ListItem>
    <asp:ListItem>Bukit Merah East NPC</asp:ListItem>
    <asp:ListItem>Rochor NPC</asp:ListItem>
    <asp:ListItem>Marina Bay NPC</asp:ListItem>
</asp:DropDownList>
<br />
<br />
The following case will be assigned to this selected officer&nbsp;
    <asp:DropDownList ID="DDLpolice" runat="server" DataTextField="dropdownpolice" DataValueField="dropdownpolice" OnSelectedIndexChanged ="DDLpolice_SelectedIndexChanged1" style="height: 22px"
    AppendDataBoundItems="true" AutoPostBack="True">
<asp:ListItem Value="-1">Select Officer</asp:ListItem>
    </asp:DropDownList>




問題出在您的測試內容和垃圾文本上。

加:

#assigngw td {
  word-wrap:break-word;
}

這將允許每個單元格在不適合的長句子上打破並且將阻止它增加網格視圖的大小。

編輯

嘗試這個

.gridview {
    width: 100%; 
    word-wrap:break-word;
    table-layout: fixed;
}

這里的關鍵是table-layout: fixed; 因為它迫使細胞適合桌子而不是桌子擴展以適應細胞。

更新了jsFiddle

您也可以將gridview放在div中,就像這樣

<div style="width:100%;overflow:scroll;"> <i>your gridview here</i> </div>

這樣,gridview不會超出頁面寬度。 但是用戶將在頁面上垂直滾動以查看所有gridview內容。

它是行中沒有空格的長文本,它將網格推出。 你需要添加這個樣式屬性word-wrap:break-word; 如果您希望文本中斷,請到單元格。

 <style type="text/css">
        .tblgridview {
            width: 100%;
            word-wrap: break-word;
            table-layout: fixed;
            font-size: smaller;
            overflow: scroll;
        }
    </style>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM