Sunday, May 29, 2011

Gridview fixed header

<%@ Page Language="VB" AutoEventWireup="False"
EnableSessionState="true" EnableViewState="False" %&gt
<%@ Import Namespace="System.Data" %&gt
<%@ Import Namespace="System.Data.Odbc" %&gt
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt
<script language ="vbscript" runat ="server" &gt
</script&gt
<html xmlns="http://www.w3.org/1999/xhtml" &gt
<head runat="server"&gt
<title&gtUntitled Page</title&gt
<style type ="text/css" &gt
.gridHeader
{
POSITION: relative;
/*IE5+ only*/
top: expression(parentNode.parentNode.parentNode.parentNode.scrollTop-2);
left:expression(parentNode.parentNode.parentNode.parentNode.scrollLeft);
z-index: 99;
}
</style&gt
</head&gt
<body&gt
<form id="form1" runat="server"&gt
<div&gt
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionStringcountrystate %&gt"
ProviderName="<%$ ConnectionStrings:ConnectionStringcountrystate.ProviderName %&gt"
SelectCommand="select * from gd_master"&gt</asp:SqlDataSource&gt
<asp:Panel ID="Panel1" runat="server" Height="280px" Style="z-index: 100; left: -82px;
overflow: auto; position: absolute; top: 54px" Width="1537px"&gt
<asp:GridView ID="GridView2" runat="server" BackColor="#CCCCCC" BorderColor="#999999"
BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2"
DataSourceID="SqlDataSource1" ForeColor="Black" Height="210px"
Style="z-index: 135; left: 80px; position: absolute; top: -3px" Width="279px"&gt
<FooterStyle BackColor="#CCCCCC" /&gt
<Columns&gt
<asp:CommandField ShowSelectButton="True" /&gt
</Columns&gt
<RowStyle BackColor="White" /&gt
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /&gt
<PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" /&gt
<HeaderStyle BackColor="Black" CssClass="gridHeader" Font-Bold="True" ForeColor="White" /&gt
</asp:GridView&gt
</asp:Panel&gt
</div&gt
</form&gt
</body&gt

</html&gt