gpt4 book ai didi

c# - 我如何使我的 gridview 100% 适合页面

转载 作者:行者123 更新时间:2023-11-30 19:10:32 25 4
gpt4 key购买 nike

如何使我的 gridview 很好地适应屏幕。我添加了这个属性 width="100%"i。然而,我的 gridview 仍然超出了我将其设置为 100% 的页眉宽度。

enter image description here

这是我第一次尝试的 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 的大小。

编辑

试试这个

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

这里的关键是 table-layout: fixed; 因为它强制单元格适合表格而不是表格扩展以适合单元格。

已更新 jsFiddle

关于c# - 我如何使我的 gridview 100% 适合页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17338904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com