ASP.Net Interview Questions and Answers
<< Previous Question Next Question >>
 Question: 2301 Page Views: 

How can you enable automatic paging in DataGrid?



Posted By: Avi Date: 28 October 2009 06:05:09 AM
 Answer:

To use the built-in paging of DataGrid, set the AllowPaging property to true and the PageSize property to the number of items to be displayed per page.

We can also specify the style of the paging controls. Paging controls are LinkButton controls which we can choose either in "Next and Previous" format or Page Numbers format, and these allow users to jump to a specific page. You can specify how many numbers are displayed; if there are more pages, an ellipsis ( … ) is displayed next to the numbers.

We must also create an event-handling method that responds when users click on a paging control.


Posted By: eTechPlanet


Date: 28 October 2009 06:05:09 AM

In order to enable paging in Datagrid you need to (very short version):

* Set the "AllowPaging" property to true.
* In PageIndexChanged event handler set the current PageIndex clicked.
Below is an example in C#:

//Declaring DataGrid
protected System.Web.UI.WebControls.DataGrid DataGrid1;
//Binding DataGrid with a Data Source (DataSet in our Case)
DataGrid1.DataSource = dataSet1;
DataGrid1.DataBind();
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.GridPageIndexChanged);
//Implement the EventHandler
private void GridPageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
//Bind the DataGrid again with the Data Source
DataGrid1.DataSource = dataSet1;
DataGrid1.DataBind();
}


Posted By: Johndecruse


Date: 10 February 2010 02:42:02 AM
Post a better Answer if you have
 
(Will show your Gravatar icon)  
  Country flag

Loading
Enter the text as shown in the image 2e9qO8
Related Questions
ASP.Net : Is it possible to look at the IL for an assembly?

Is it possible to look at the IL for an assembly?

Yes, one can view IL for an assembly. IL stands for Intermediate Language. It can be viewed with a t....
Category: ASP.Net Date: 10/1/2010 3:14:14 AM
ASP.Net : What are the advantages of pre-compilation in asp.net?

What are the advantages of pre-compilation in asp.net?

1. the performance is increased as the site has already been compiled and when it is requested no ti....
Category: ASP.Net Date: 10/1/2010 2:48:19 AM
ASP.Net : Which class manages the view state of ASP.NET server controls, including pages?

Which class manages the view state of ASP.NET server controls, including pages?

StateBag class. This class can not be inherited. Synatx:- Public NotInheritable Class StateBag _ I....
Category: ASP.Net Date: 10/1/2010 2:35:13 AM
ASP.Net : List the pre-processor words ?

List the pre-processor words ?

#if #else #endif #define #undef #warning #error #line #region #endregion are the main used directiv....
Category: ASP.Net Date: 10/1/2010 2:25:14 AM
ASP.Net : Can we prevent a browser from caching an ASPX page?

Can we prevent a browser from caching an ASPX page?

Yes , it can be prevented by using Response.Cache.SetNoStore() method.
Category: ASP.Net Date: 10/1/2010 2:04:13 AM