Fix Gridview Header While Scrolling in

gridview header fixed on scroll in,

In this article we discus about Gridview Header Fix while scrolling data, whenever we want to display large amount of data in Gridview and that they is small space is available to display gridview data in web pages. This kind of suitable can handle by using Gridview header fix with scrollable. let me show you how to achieve this and also you can see in above image


In this articles i have used my previous project database Create Book Inventory Project.

To Fix Gridview Header :

Gridview Properties :

  • GridView1 ShowHeader = "false"

now create gridview header by using HTML Table and places the GridView just below the Table. So the header row is always fixed there and we can scroll the GridView and see the data.

HTML Markup : Create HTML Design

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridviewFixedHeader.aspx.cs" Inherits="GridviewFixedHeader" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <style type="text/css">
         border:1px solid #FF0040;
    <form id="form1" runat="server">
     <div class="grd_header_table">
        <table bgcolor="#FF0040" rules="all" >
                <td style ="width:55px;">BookID</td>
                <td style ="width:260px;">Book Name</td>
                <td style ="width:114px;">Author</td>
                <td style ="width:206px;">Pub. Name</td>
                <td style ="width:100px;">Pub. Date</td>
        <div style ="height:130px; width:600px; overflow:auto;">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            ShowHeader = "False" Width ="580px" >
                    <asp:BoundField DataField="Book_Id" />
                    <asp:BoundField DataField="Book_name" />
                    <asp:BoundField DataField="Book_author" />
                    <asp:BoundField DataField="Book_Publisher_name" />
                    <asp:BoundField DataField="Book_Published_date" />

C# Coding

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class GridviewFixedHeader : System.Web.UI.Page
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbCon"].ToString());
    string query;

    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
    private void FillGridData()
        query = "select * from Book";
        SqlDataAdapter da = new SqlDataAdapter(query, con);
        DataSet ds = new DataSet();
        da.Fill(ds, "book");
        GridView1.DataSource = ds;


Post a Comment