冻结Gridview标头无法正常工作

时间:2014-07-08 05:35:23

标签: c# asp.net c#-2.0

我需要在滚动网格视图上冻结网格视图标题。将数据分配给数据表并将其绑定到名为“report”的gridview。我尝试了很多,但它没有用..任何人都可以帮助我吗?

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
    <ContentTemplate>
        <center>
           <asp:Label ID="mess" runat="server" Font-Bold="true" ForeColor="Red"></asp:Label>
        </center>                        
        <div class="table_outer_n">
           <asp:GridView ID="report" runat="server"  Width="100%" HeaderStyle-CssClass="Freezing"></asp:GridView>
           <asp:GridView ID="gvDetails" runat="server" Visible="true"></asp:GridView> 
        </div>
     </ContentTemplate>
     <Triggers>
        <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
        <asp:PostBackTrigger ControlID="report" />
        <asp:PostBackTrigger ControlID="gvDetails" />
        <asp:PostBackTrigger ControlID="btndwn" />
      </Triggers>
</asp:UpdatePanel> 

//Code behind
DataTable claims = new DataTable();   
//.....datatable codes goes here
dr["REMARKS"] = remarks;
dr["VALIDATION"] = validation;
DataRow dr = claims.NewRow();
claims.Rows.Add(dr);

report.DataSource = claims;
report.DataBind();

//css
.Freezing {
   position:relative ;
   top:expression(this.offsetParent.scrollTop);
   z-index: 10;
}

2 个答案:

答案 0 :(得分:1)

请按照link On CodeProject

进行操作

您需要将标题样式设置为

<style type="text/css">
    .FixedHeader {
        position: absolute;
    }     
</style>   

HeaderStyle-CssClass="FixedHeader"

或者评论建议此answer on stackoverflow也可以帮助您

答案 1 :(得分:1)

你可以这样试试:

 <div style ="height:200px; width:617px; overflow:auto;">
// Your Grid View

 <asp:GridView ID="report" runat="server"  Width="100%" >
</asp:GridView>
 </div>

来源: Source code with Live Demo