Click here to Skip to main content
15,915,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to prevent gridview header from hiding while scrolling down
Posted

Hi,
Apply this style sheet to your gridview

CSS
 .HeaderStyle
{
font-family:verdana;
font-size:x-small;
width:100%;
position:relative;
top:expression(this.offsetParent.scrollTop-1);
margin-left:0;
}
 
Share this answer
 
Comments
aparnaChandras 18-Apr-14 1:55am    
I did the same but it not work.my gridview is in content palce holder.
Bh@gyesh 18-Apr-14 2:10am    
Can you please paste your code?
aparnaChandras 18-Apr-14 4:30am    
.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="RefListExcel01" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script src="javaScript\SRLJScript.js.aspx" type="text/javascript">

</script>


<style type="text/css">


.style1
{
background-color: white;
width: 815px;
}

.style2
{
width: 870px;
}

.style3
{
width: 892px;
}
.style4
{
background-color: white;
width: 892px;
height: 20px;
}

.style5
{
background-color: white;
width: 815px;
height: 20px;
}

</style>


<asp:Content ID="Content2" runat="server"
contentplaceholderid="ContentPlaceHolder1">
<table class="header">
<tr >
<td>
<img alt="Logo" class="logo" src="images/logo.jpg" /></td>
</tr>
Home.aspx
<tr>
<td class="headerMenu">
<table class="headerMenu">
<tr>
<td class="link">
Home</td>
<td class="link" >
Qubik Search</td>
<td class="link">
Short Reference List</td>
<td class="link">
Long Reference List</td>
<td class="link">
Reports</td>
</tr>
</table>
</td>
</tr>
</table>
<!--PAGE CONTENTS -->


<table class="SearchFieldText">

<tr><td>

<asp:Button ID="btnExport" runat="server" onclick="btnExport_Click" Text="Export To Excel" class="filterTableButton"/>
</td>
<td>
<form id="f1" name="f1" action="javascript:void(0)" önsubmit="searchpage()" >
<input id="t1" type="text" name="t1" />
<input id="button" type="button" value="FIND" name="b1" önclick="searchpage()" />
</form>
</td>
</tr>
<tr>
<td>
<asp:Panel ID="Panelgrid" runat="server" ScrollBars="Vertical"
Height="500px" Width="800px">

<asp:GridView ID="GridViewSRL" runat="server" AutoGenerateSelectButton="True" OnLoad="GridViewSRL_Load"
AllowSorting ="true" OnSorting="GridViewSRL_Sorting" >
<HeaderStyle CssClass="fixedHeader"/>
<rowstyle wrap="False" backcolor="White" bordercolor="#CCCCFF" borderstyle="Outset"
="" borderwidth="1px" cssclass="rowHover">
<SelectedRowStyle BackColor="#0099FF" />






<asp:HiddenField ID="hndSelectedValue" runat="server" Value="" />
<asp:TextBox ID="txtSQL" runat="server" BackColor="#ECFFFE" Font-Size="Medium"
Height="0" Text="" TextMode="MultiLine" Visible="False" Width="0">
</td>
</tr>
<tr>
<td class="colorHeader"></td>
</tr>
</table>








and
.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.W
Hi,

Change style as below:

CSS
.HeaderStyle
{
font-family:verdana;
font-size:x-small;
position:absolute;
margin-left:0;
}
 
Share this answer
 
Comments
aparnaChandras 18-Apr-14 7:10am    
it still not work
Bh@gyesh 18-Apr-14 7:19am    
Hi,
Its working at my side. Do as follows:
1) Add following stylesheet in your page under <style> tag
.HeaderStyle
{
font-family:verdana;
font-size:x-small;
position:absolute;
margin-left:0;
}

2) Now, following is gridview declaration in .aspx page.
<asp:GridView ID="GridViewSRL" runat="server" AutoGenerateSelectButton="True" OnLoad="GridViewSRL_Load" AllowSorting ="true" OnSorting="GridViewSRL_Sorting" HeaderStyle-CssClass="HeaderStyle" AutoGenerateColumns="true" OnRowDataBound="GridViewSRL_RowDataBound">


3) Add rowdatabound event in .cs file
protected void gvDistricts_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex == 0)
e.Row.Style.Add("height", "50px");
}
}
now check.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900