In this article I will explain with an example, how to make the ListView Scrollable i.e. Freezed or Fixed ListView Header Row and add a vertical Scrollbar for scrolling the Data rows in ASP.Net using C# and VB.Net.
The ListView will be displayed as HTML Table and the Header will be freezed (fixed) and Data rows will be made Scrollable using the ASPSnippets Scrollable Table jQuery Plugin.
 
 
Scrollable Table jQuery Plugin
This article makes use of the Scrollable Table jQuery Plugin which can be downloaded using the link below.
 
 
Database
Here I am making use of Microsoft’s Northwind Database. The download and install instructions are provided in the following article.
 
 

HTML Markup
The ListView control will be displayed in HTML Table Layout. An HTML Table has been placed inside the LayoutTemplate with Table Header.
The GroupPlaceHolder will display the contents from GroupTemplate. The GroupTemplate contains a PlaceHolder wrapped within TR Tags.
The PlaceHolder will display the contents from the ItemTemplate where I have placed the TD cells populated from the database.
<asp:ListView ID="lvCustomers" runat="server" GroupPlaceholderID="groupPlaceHolder1"
    ItemPlaceholderID="itemPlaceHolder1">
    <LayoutTemplate>
         <table id = "ListViewTable" cellpadding="0" cellspacing="0" border = "1" style = "border-collapse:collapse">
            <tr>
                <th>
                    CustomerId
                </th>
                <th>
                    ContactName
                </th>
                <th>
                    Country
                </th>
            </tr>
            <asp:PlaceHolder runat="server" ID="groupPlaceHolder1"></asp:PlaceHolder>
        </table>
    </LayoutTemplate>
    <GroupTemplate>
        <tr>
            <asp:PlaceHolder runat="server" ID="itemPlaceHolder1"></asp:PlaceHolder>
        </tr>
    </GroupTemplate>
    <ItemTemplate>
        <td>
            <%# Eval("CustomerId") %>
        </td>
        <td>
            <%# Eval("ContactName") %>
        </td>
        <td>
            <%# Eval("Country") %>
        </td>
    </ItemTemplate>
</asp:ListView>
 
 
Namespaces
You will need to import the following namespaces.
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
 
VB.Net
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
 
 
Binding the ListView control
Inside the Page Load event, the ListView control is populated with records from Customers Table of the Northwind database.
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        this.BindListView();
    }
}
 
private void BindListView()
{
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "SELECT CustomerId, ContactName, Country FROM Customers";
            cmd.Connection = con;
            using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
            {
                DataTable dt = new DataTable();
                sda.Fill(dt);
                lvCustomers.DataSource = dt;
                lvCustomers.DataBind();
            }
        }
    }
}
 
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Me.BindListView()
    End If
End Sub
 
Private Sub BindListView()
    Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
    Using con As New SqlConnection(constr)
        Using cmd As New SqlCommand()
            cmd.CommandText = "SELECT CustomerId, ContactName, Country FROM Customers"
            cmd.Connection = con
            Using sda As New SqlDataAdapter(cmd)
                Dim dt As New DataTable()
                sda.Fill(dt)
                lvCustomers.DataSource = dt
               lvCustomers.DataBind()
            End Using
        End Using
    End Using
End Sub
 
 
Freezing ListView Header
Inside the jQuery document ready event handler, the Scrollable Table jQuery Plugin is applied to the HTML Table of the ListView control.
Note: For more information on the Scrollable Table Plugin, please refer my article Make Scrollable Table in HTML with Fixed Header using jQuery.
 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="Scripts/ScrollableTablePlugin_1.0_min.js"></script>
<script type="text/javascript">
    $(function () {
        $('#ListViewTable').Scrollable({
            ScrollHeight: 300
        });
    });
</script>
 
 
Screenshot
ASP.Net Scrollable ListView: Freeze (Fixed) Header of ListView in ASP.Net
 
 
Browser Compatibility

The above code has been tested in the following browsers.

Internet Explorer  FireFox  Chrome  Safari  Opera 

* All browser logos displayed above are property of their respective owners.

 
 
Demo
 
 
Downloads