Categories: ASP.NET

GridView with Scrollbars in ASP.NET – Easy Step by Step

Today I am here to share something to you. This is simpler as never but I bet, you are searching for this since long. In this article, we will learn how to create GridView with Scrollbars in ASP.NET.

Published by

Today I am here to share something to you. This is simpler as never but I bet, you are searching for this since long. In this article, we will learn how to create GridView with Scrollbars in ASP.NET.

GridView with Scrollbars in ASP.NET

If you have developed any web application using ASP.NET, you must have used GridView, if you are beginner and learning ASP.NET, this will tell you how to make display GridView with Scrollbars. As we know, we can Paginate data in GridView, but putting a Scrollbar is really confusing as it is not in default properties of GridView control.

Lets design a web form and insert a GridView. I am using no designs and just a form and dragged and auto formatted GridView control in this tutorial.

Lets see the code for this web form.

<div align="center">
 <asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" cellpadding="4"
datakeynames="DistID" datasourceid="SqlDataSource1" forecolor="#333333" gridlines="None" 
height="240px" width="667px"> 
<AlternatingRowStyle BackColor="White" ForeColor="#284775" /> 
<Columns> 
<asp:BoundField DataField="DistID" HeaderText="DistID" InsertVisible="False" ReadOnly="True" SortExpression="DistID" /> 
<asp:BoundField DataField="StateID" HeaderText="StateID" SortExpression="StateID" /> 
<asp:BoundField DataField="DistName" HeaderText="DistName" SortExpression="DistName" /> 
<asp:BoundField DataField="DistDesc" HeaderText="DistDesc" SortExpression="DistDesc" /> 
</Columns> 
<EditRowStyle BackColor="#999999" /> 
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> 
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> 
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> 
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> 
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> 
<SortedAscendingCellStyle BackColor="#E9E7E2" /> 
<SortedAscendingHeaderStyle BackColor="#506C8C" /> 
<SortedDescendingCellStyle BackColor="#FFFDF8" /> 
<SortedDescendingHeaderStyle BackColor="#6F8DAE" /> 
</asp:gridview> 
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:ConnectionString1 %>" 
selectcommand="SELECT * FROM [Districts]"></asp:sqldatasource> 
</div>

I have bind data from one of my projects, this is schema of Address and table is District List. Lets run the Web form, our output is:

Related Post

This is how it will list record and entire page will have GridView data. To fix this, I have added just a style tag to Div and some code inside that tag. Below is code.<

..style="height:400px; overflow:auto"..
//You can change overflow:auto to overflow:scroll but that will show both Scrollbar and always. 
//Above will show Vertical Scrollbar only when the Height of GridView exceeds than assigned height.

After adding above code, I refreshed the browser, Now this is the new and required layout of GridView with Scrollbars.

You can download the source code from JohnBhatt.com for free. Enjoy. Till then subscribe our feeds and get updated. You can also drop a comment below to suggest us improving.

Advertisement
Share
Published by

Recent Posts

Understanding Functions in C: Best Beginner’s Guide

In this blog, we'll explore the concept of Functions in C, their syntax, type of… Read More

Last modified 2 days ago

What is Queue in Data Structure and Algorithm, Concept of Queue in DSA Explained

First of all we have to understand what is queue? Queue in Data Structure and… Read More

Last modified 1 week ago

How To Change Bootstrap 5 Theme between Light and Dark Mode in any webpage using JavaScript & CSS?

In this article, we will learn how to add Dark and Light Mode switching functionality… Read More

Last modified 3 weeks ago