for fixing header in gridview please follow this it will might help you..
1)make some changes in your aspx page like this..
place 2 divs like this..
<div id="HeaderDivACT">
</div>
<div id="DataDivACT" style="overflow: auto; width: 100%;" önscroll="Onscrollfnction();">
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false" xmlns:asp="#unknown">
</asp:gridview>
</div>
2) now call one javascript function while your gridview will complete after loading data from database..
means after databinding of gridview you need to call this function
<script language="javascript" type="text/javascript">
var sp = 0;
function freezHeader(idGVDailyActivity) {
try {
var DataGridObj = document.getElementById(idGVDailyActivity);
if (DataGridObj != null) {
if (DataGridObj) {
if (DataGridObj.clientWidth == 0) {
setTimeout("freezHeader(" + idGVDailyActivity + ")", 2000);
return;
}
var DataDivObj = document.getElementById('DataDivACT');
var HeaderDivObj = document.getElementById('HeaderDivACT');
var HeadertableObj = HeaderDivObj.appendChild(document.createElement('table'));
DataDivObj.style.paddingTop = '0px';
var DataDivWidth = $(window).width() - 20;
DataDivObj.style.width = '5000px';
HeaderDivObj.className = DataDivObj.className;
HeaderDivObj.style.cssText = DataDivObj.style.cssText;
HeaderDivObj.style.overflow = 'auto';
HeaderDivObj.style.overflowX = 'hidden';
HeaderDivObj.style.overflowY = 'hidden';
HeaderDivObj.style.height = '30px';
HeaderDivObj.style.borderBottomWidth = '0px';
HeadertableObj.className = DataGridObj.className;
if (DataGridObj.style == null)
return;
HeadertableObj.style.cssText = DataGridObj.style.cssText;
HeadertableObj.border = '1px';
HeadertableObj.rules = 'all';
HeadertableObj.cellPadding = DataGridObj.cellPadding;
HeadertableObj.cellSpacing = DataGridObj.cellSpacing;
var Row = HeadertableObj.insertRow(0);
Row.className = DataGridObj.rows[0].className;
Row.style.cssText = DataGridObj.rows[0].style.cssText;
Row.style.fontWeight = 'bold';
for (var iCntr = 0; iCntr < DataGridObj.rows[0].cells.length; iCntr++) {
var spanTag = Row.appendChild(document.createElement('td'));
spanTag.innerHTML = DataGridObj.rows[0].cells[iCntr].innerHTML;
var width = 0;
if (spanTag.clientWidth > DataGridObj.rows[1].cells[iCntr].clientWidth) {
width = spanTag.clientWidth;
}
else {
width = DataGridObj.rows[1].cells[iCntr].clientWidth;
}
if (iCntr <= DataGridObj.rows[0].cells.length - 2) {
spanTag.style.width = width + 'px';
}
else {
spanTag.style.width = width + 20 + 'px';
}
spanTag.style.textAlign = 'center';
DataGridObj.rows[1].cells[iCntr].style.width = width + 'px';
}
var tableWidth = DataGridObj.clientWidth;
DataGridObj.rows[0].style.display = 'none';
HeaderDivObj.style.width = DataDivWidth + 'px';
DataDivObj.style.width = DataDivWidth + 'px';
DataGridObj.style.width = tableWidth + 'px';
HeadertableObj.style.width = tableWidth + 20 + 'px';
DataDivObj.style.height = ($(window).height() - 305) + 'px';
DataDivObj.scrollTop = sp;
}
}
} catch (e) { }
}
function Onscrollfnction() {
var scPos = document.getElementById('scrlPos');
var div = document.getElementById('DataDivACT');
var div2 = document.getElementById('HeaderDivACT');
sp = div.scrollTop;
div2.scrollLeft = div.scrollLeft;
return false;
}
3) call this function like this
$(document).ready(function() { freezHeader('<%= GVDailyActivity.ClientID %>'); });