c# - GridView 固定 header 溢出容器

标签 c# html css asp.net gridview

我在 Div 容器中有一个带有卡住标题的 gridview。当 gridview 中标题列的数量不超过容器的数量时,它工作正常,如果我在 gridview 中添加更多标题列,它会溢出 div 容器。

enter image description here

    <%@ 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" 的出现,这样就不会再产生不需要的重叠效果。

关于c# - GridView 固定 header 溢出容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38326919/

相关文章:

javascript - Cloud Foundry 不兼容 IE?

c# - EntityFramework 包版本 ="6.1.3"和 Web 配置版本 6.0.0.0?

在 Task.WhenAll 中执行许多任务时的 C# 线程

html - Wordpress 备用移动版本 Logo

html - 使用 ruby​​ 核心库解析 HTML? (即不需要 gem )

html - 我的子 DIV 超出了父级。无固定/绝对定位

html - 解析网格内容

C# 结构和类变量值

c# - 无法在我的 WPF 网格中创建列

JavaScript 无法在简单的测试页面上运行