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.
HTML
<%@ 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">
   <title></title>
    <style type="text/css">
        .auto-style1
        {
            width: 115px;
        }
    </style>
</head>
<body>
    <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" >
            <tr>
               <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>
            </tr>
        </table>
        </div>
        <div style ="height:130px; width:500px; overflow:auto;">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
ShowHeader="False"
DataSourceID="SqlDataSource1" Width="480px">
                <AlternatingRowStyle BackColor="#FF99FF" />
                <Columns>
                    <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" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SPEED_SOLUTIONConnectionString %>" SelectCommand="SELECT [EmpId], [EmpName], [City], [State], [Country] FROM [EmpDetails]"></asp:SqlDataSource>
       </div>
    </form>
</body>
</html>

Related Posts:

  • 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 scro… Read More
  • Auto Generate Row Number in GridView The GridView control is the successor to the DataGrid and extends it in a number of ways. While developing GridView control in ASP.NET, programmers often requires to display row number in GridView controls. Auto Generate… Read More
  • How To Use Grid View Page Index Changing In Asp.Net Here I Will Explain How to use Page Index/Pagination In Grid View.With various types of paging in ASP.NET. We use C# code to bind the SQL data with a Grid View control and use the following simple steps to mak… Read More
  • How To Add Dynamic Controls Into Gridview in Asp.net How to add dynamic controls to the Grid view in the Code Behind page. when the page is refresh or the page is Post Back the dynamically created controls will disappear from Grid View, … Read More
  • How to add Data Item Index in Grid View In Asp.Net The GridView control is the successor to the DataGrid and extends it in a number of ways. While developing GridView control in ASP.NET, programmers often requires to display row number in GridView controls. This can b… Read More

0 comments::

Post a Comment

Copyright © 2025 DotNet-Ashok