Paging Grid Data in .NET

Print ANSI/AIM Code 128 in .NET Paging Grid Data
Paging Grid Data
Code 128 Code Set C Scanner In .NET Framework
Using Barcode Control SDK for .NET framework Control to generate, create, read, scan barcode image in Visual Studio .NET applications.
Paging came along with the introduction of the DataGrid control. This simple event actually involves quite a bit of work behind the scenes. When the user requests the next page of data, the browser makes a round trip to the server to determine the next page of data, and then renders the next page of data on the client. With .NET, this is now a trivial task, requiring only that you set a few properties and wire up one event. If you want to handle your own paging, you can do that by setting the CustomPaging property. The following code automatically generates the data items from the data source and then sets the style of paging: <%@ Import NameSpace="System.Data" %> <html> <head> <title>Hungry Minds 9...</title> <script language="C#" runat="server"> DataSet ds = new DataSet(); void Page_Load(Object sender, EventArgs e) { if (!IsPostBack) BindData(); } void LoadDataSource() { ds.ReadXml(Page.MapPath("data.xml")) } void BindData() { LoadDataSource(); Paging.DataSource = ds; Paging.DataBind(); } void PageIndexChanged(Object sender, DataGridPageChangedEventArgs e) { Paging.CurrentPageIndex = e.NewPageIndex; BindData(); } </script> </head> <body> <img src="logo.gif"> <br> <font face="verdana" size="5">DataGrid Paging Example...</font> ;
Create Code128 In Visual Studio .NET
Using Barcode generator for VS .NET Control to generate, create Code 128 image in .NET framework applications.
<hr> <form method="post" runat="server" ID="Form1"> <asp:DataGrid ID="Paging" AutoGenerateColumns="true" OnPageIndexChanged="PageIndexChanged" ShowHeader="True" BorderColor="#6699cc" BorderWidth="1" CellPadding="1" Font-Name="verdana" Font-Size="10pt" HeaderStyle-BackColor="#6699cc" AllowPaging="true" PageSize="4" PagerStyle-NextPageText="[Next Page]" PagerStyle-PrevPageText="[Previous Page]" PagerStyle-HorizontalAlign="center" RunAt="server"> </asp:DataGrid> </form> <hr> </body> </html> Launch your browser and navigate to DataGridPaging.aspx; the screen should look like Figure 10-11.
Recognizing Code 128A In .NET Framework
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
Figure 10-11: DataGridPaging.aspx, as displayed in Internet Explorer Select the Next or Previous hyperlink at the bottom of the data grid. The next or previous page of data is fetched from the data source and displayed in the grid. You can adjust the number of pages to display, the style of the paging buttons, and determine the number of pages in your data source. With the Data Grid control, you have complete control over paging. If you prefer, you can enable the CustomPaging property and implement your own paging logic.
Create Bar Code In .NET
Using Barcode encoder for VS .NET Control to generate, create bar code image in VS .NET applications.
To enable paging, you must first turn it on by setting the Paging property to True (by default, this is turned off). So, if your data source has many rows, it will appear as one long continuous list of tabular data on your page. Once Paging is set to True, you can set the other paging properties to control the display and the type of paging. You also need to code the PageIndexChanged event to handle when the user selects a new page of data. Typically, in this event, you need to set the CurrentPageIndex to the index of the page you want to display, and then call the DataBind method to rebind the data to the grid. The PageIndexChanged event takes the DataGridPageChangedEventArgs object as a parameter. This object has the following properties: CommandSource: Indicates the source of the command NewPageIndex: Gets the index of the page selected by the user from the page selection element of the control You can also set the paging mode property PagerMode to one of two values: NextPrev: Displays Previous and Next buttons to access the next and previous pages NumericPages: Displays numbered buttons to access pages directly By default, when paging is turned on, the Next and Previous links are displayed as less than (<) and greater than (>) symbols. As in the DataGridPaging.aspx code example, the links are displayed as "[Next Page]" and "[Previous Page]". The NextPageText and PrevPageText can be set to any string value you choose. If you set the PagerMode to NumericPages, the links at the bottom of the grid for paging are displayed as numbers from 1 to n. Try it! Insert the PagerStyleMode="NumericPages" in the DataGrid.
Decode Barcode In VS .NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in VS .NET applications.
Sorting Grid Data
Generate Code128 In C#
Using Barcode maker for VS .NET Control to generate, create Code-128 image in Visual Studio .NET applications.
One last important feature of the DataGrid control is sorting. Just like paging, you only need to set a few properties and then handle the Sort event. Launch your browser and navigate to DataGridSorting.aspx; the screen should look like Figure 10-12.
Code 128B Generation In Visual Studio .NET
Using Barcode creation for ASP.NET Control to generate, create Code 128 Code Set B image in ASP.NET applications.
Figure 10-12: DataGridSorting.aspx, as displayed in Internet Explorer Take a look at the following code: <%@ Import NameSpace="System.Data" %> <html> <head> <title>Hungry Minds 9...</title> <script language="C#" runat="server">
Creating ANSI/AIM Code 128 In VB.NET
Using Barcode generator for .NET Control to generate, create Code 128 Code Set C image in .NET applications.
String SortOrder; void Page_Load(Object sender, EventArgs e) { if (!IsPostBack) { if (SortOrder == null) SortOrder = "name"; Paging.DataSource = LoadDataSource(); Paging.DataBind(); } } ICollection LoadDataSource() { DataSet ds = new DataSet(); ds.ReadXml(Page.MapPath("data.xml")) if (SortOrder != null) ds.Tables[0].DefaultView.Sort = SortOrder; return ds.Tables[0].DefaultView; } void Sort_Grid(Object sender, DataGridSortCommandEventArgs e) { SortOrder = e.SortExpression.ToString(); SortMsg.Text = "<br>Grid sort order is <b>" + SortOrder + "</b>"; Paging.DataSource = LoadDataSource(); Paging.DataBind(); } </script> </head> <body> <img src="logo.gif"> <br> <font face="verdana" size="5">DataGrid Sorting Example...</font> <hr> <form method="post" runat="server" ID="Form1"> <asp:DataGrid ID="Paging" AutoGenerateColumns="true" OnSortCommand="Sort_Grid" ShowHeader="true" BorderColor="#6699cc" BorderWidth="1" CellPadding="1" ;
Create USS Code 39 In .NET Framework
Using Barcode generation for .NET Control to generate, create Code 3/9 image in .NET applications.
Font-Name="verdana" Font-Size="10pt" HeaderStyle-BackColor="#6699cc" AllowSorting="true" RunAt="server"> </asp:DataGrid> <asp:Label ID="SortMsg" Runat="server" /> </font> </form> <hr> </body> </html> To enable sorting, you set the AllowSorting property of the DataGrid to True and set the OnSortCommand to point to the name of your sorting event. When sorting is enabled, the grid header columns are displayed as "clickable" links, allowing you to sort by any data column in the grid. In the DataGridSorting.aspx code, the Sort_Grid takes either of the following as a parameter: CommandSource: Gets the source of the command SortExpression: Gets the expression used to sort the DataGrid control In the previous example, you extract the SortExpression into your SortOrder string variable and then use this value in your LoadDataSource routine. In the DataGridSorting.aspx code, you set the Sort property of the DefaultView in your data set and then call the DataBind method of the DataGrid to sort and redisplay the grid data.
Make ANSI/AIM Code 128 In Visual Studio .NET
Using Barcode generation for Visual Studio .NET Control to generate, create USS Code 128 image in .NET applications.
Summary
Barcode Generation In Visual Studio .NET
Using Barcode creation for VS .NET Control to generate, create barcode image in Visual Studio .NET applications.
This chapter covered how to format the grid using different styles. It also looked at using the Columns property of the DataGrid control to display data items as different column types. In addition, you saw how to enable paging and sorting in the DataGrid. With the help of the DataGrid and all of its built-in functionality, you can display, page, and sort your data with a minimal amount of coding.
Ames Code Creation In Visual Studio .NET
Using Barcode creation for .NET Control to generate, create 2 of 7 Code image in VS .NET applications.
11:
Generating Bar Code In Java
Using Barcode encoder for Java Control to generate, create bar code image in Java applications.
Draw GTIN - 128 In Java
Using Barcode creation for Java Control to generate, create GS1-128 image in Java applications.
Scan Bar Code In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
Code-39 Reader In VS .NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
Bar Code Maker In Java
Using Barcode maker for Java Control to generate, create barcode image in Java applications.