我在Div容器中有一个冻结标题的gridview。当gridview中的标题列的数量不超过容器的数量时,如果我将更多的header列添加到gridview中,它会导致div容器溢出,因此效果很好。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test2.aspx.cs" Inherits="Test2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.header { position:absolute; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="overflow:scroll; height:250px; width:600px;" >
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
CellPadding="4" ForeColor="#333333" Width="600px">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" HeaderStyle-Width="271px" />
<asp:BoundField DataField="Branch" HeaderText="Branch" HeaderStyle-Width="91px" />
<asp:BoundField DataField="City" HeaderText="City" HeaderStyle-Width="194px" />
<asp:BoundField DataField="Contact" HeaderText="NewColumn1" HeaderStyle-Width="194px" />
<asp:BoundField DataField="Email" HeaderText="NewColumn2" HeaderStyle-Width="194px" />
</Columns>
<HeaderStyle CssClass="header" BackColor="#7961da"
Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
</asp:GridView>
</div>
</form>
</body>
</html>
/ Aspx.cs代码/
protected void Page_Load(object sender, EventArgs e)
{
DataTable table = new DataTable();
table.Columns.Add("Name");
table.Columns.Add("Branch");
table.Columns.Add("City");
table.Columns.Add("Contact");
table.Columns.Add("Email");
for (int i = 0; i < 80; i++)
{
DataRow row1 = table.NewRow();
List<string> report1 = new List<string>();
report1.Add("XYZ");
report1.Add("ABC");
report1.Add("PQR");
row1["Name"] = "MyName";
row1["Branch"] = "MyBrach";
row1["City"] = "London";
row1["Contact"] = "NewColumnData1";
row1["Email"] = "NewColumnData2";
table.Rows.Add(row1);
}
GridView1.DataSource = table;
GridView1.DataBind();
请删除所有出现的内容HeaderStyle-Width="x"
,它将不再产生不希望的重叠效果。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句