Tuesday, 21 October 2014

Freeze GridView Header Row In Asp.Net

In Grid View Control You Can easily display all the collection of data and we can easily add sorting and paging, and perform in-line editing.Some time there is large no of data which makes grid view scrollable, headers will also scroll along with the other grid view contents making it difficult for the user to understand the data properly.In this situations we can freeze the header row then the user can scroll the data and see the header as fixed.

Freeze The Gridview Row
Here we set GridView ShowHeader = "false" and make a separate header for the GridView 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.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Freeze_Gridview_Header.aspx.cs" Inherits="Freeze_Gridview_Header" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <style type="text/css">
            width: 115px;
    <form id="form1" runat="server">
    <div style="width:478px;border:1px solid #084B8A;color:#ffffff;font-weight:bold;">
        <table bgcolor="#3090C7" rules="all" style="background-color: #00CC00" >
               <td class="auto-style1">EmpID</td>
                <td style ="width:180px;">EmpName</td>
               <td style ="width:90px;">City</td>
                <td style ="width:60px;">State</td>
                <td style ="width:78px;">Country</td>
        <div style ="height:130px; width:500px; overflow:auto;">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" Width="480px">
                <AlternatingRowStyle BackColor="#FF99FF" />
                    <asp:BoundField DataField="EmpId" HeaderText="EmpId" SortExpression="EmpId" />
                    <asp:BoundField DataField="EmpName" HeaderText="EmpName" SortExpression="EmpName" />
                  <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                   <asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
                    <asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SPEED_SOLUTIONConnectionString %>" SelectCommand="SELECT [EmpId], [EmpName], [City], [State], [Country] FROM [EmpDetails]"></asp:SqlDataSource>


Post a Comment

Copyright © DotNet-Ashok