For this we need to add css to headers of gridview to keep them on the top.
on the aspx page from thetoolbox. Set height to 200px and width to 200px
and scrollbars to Vertical.
Now add a gridview inside this Panel and set the datasource to populate gridview.
<form id="form1" runat="server"> <div> <asp:Panel ID="Panel1" runat="server" Height="200px" Width="200px" ScrollBars="Vertical"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" RowStyle-VerticalAlign="Bottom" OnRowDataBound="GridView1_RowDataBound"> <Columns> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" /> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" /> </Columns> <HeaderStyle CssClass="header"Height="20px" /> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [ID], [Name], [Location] FROM [Details]"> </asp:SqlDataSource> </asp:Panel> </div> </form>
01.<head runat="server">
02.<title>Creating scrollable GridView with fixed headers</title>
03.<style type="text/css">
04..header
05.{
06.font-weight:bold;
07.position:absolute;
08.background-color:White;
09.}
10.</style>
11.</head>
01.protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
02.{
03.
04.if (e.Row.RowType == DataControlRowType.DataRow)
05.{
06.if(e.Row.RowIndex == 0)
07.e.Row.Style.Add("height","40px");
08.}
09.}
Let me know.