Instructor-led online courses in ASP.NET Core, ASP.NET MVC, and ASP.NET Design Patterns. Read more...
Instructor-led online courses in ASP.NET Core, ASP.NET MVC, and ASP.NET Design Patterns. Conducted by Bipin Joshi on weekends. More details are available here.

<%@ Page %>

HOW TO: Display DataGrid in small screen area without using Paging


Paging is perhaps one of the most frequently features of DataGrid web control. Paging provides following advantages:
  • Display small set of data from huge collection
  • Save browser window area by dividing entire data into pages
Paging requires you to post back the web form each time you want to change the page. Consider a case when you have say 100 records to be displayed. This is not really huge data for the kind of application you are developing. So, you do not really need paging. At the same time, however, you want to save browser window space because displaying 100 records is taking too much of screen space. How to overcome this? Read on...

Creating web form with DataGrid

We will first create a web form that contains a DataGrid bound with a database table. We will call this web form as WebForm1. The markup looks like this:
<%@ Page Language="vb"%>
	<form id="Form1" method="post" runat="server">
		<asp:DataGrid id="DataGrid1" runat="server">
In the Page_Load event we will bind DataGrid as usual:
Dim connstr As String = 
"Integrated Security=SSPI;Initial Catalog=Northwind;
Data Source=SERVER\NetSDK"
Dim cnn As New SqlConnection(connstr)
Dim da As New SqlDataAdapter("select * from employees", cnn)
Dim ds As New DataSet()
da.Fill(ds, "employees")
DataGrid1.DataSource = ds

Creating web form that hosts this DataGrid

Now, we will create the main form on which you intend to show the Data (say DataGridHost.aspx). We will use IFRAME HTML tag that will point to WebForm1 we developed previously. Following code show that:
<%@ Page Language="vb"%>
	<iframe src="webform1.aspx">
This form may have other web control just like any other web form. Once this form gets displayed the DataGrid from WebForm1 will be shown in the IFRAME. Note that IFRAME tage is specific to Internet Explorer.

Bipin Joshi is a software consultant, trainer, author and spiritual yoga mentor having 23+ years of experience in software development. He teaches online training courses in ASP.NET Core, Angular, and Design Patterns to individuals and small groups. He is a published author and has authored or co-authored books for Apress and Wrox press. Having embraced the Yoga way of life he also teaches Ajapa Yoga to interested individuals. To know more about him click here.

Get connected : Twitter  Facebook  Google+  LinkedIn

Posted On : 26 April 2002

Tags : ASP.NET Server Controls JavaScript Data Controls

Subscribe to our newsletter

Get monthly email updates about new articles, tutorials, code samples, and how-tos getting added to our knowledge base.