Several methods of displaying a DataGrid control column number in ASP.NET
Source: Unknown Author: Unknown Recommended rating: Visits: 18
DataGrid control that displays the serial number of the column of asp.net in several ways: 2004-9-10 in aps.net Zheng Zuo multi-control data binding lot, on the function, it should belong to the most complete DataGrid, but it did not provide The function of displaying record serial numbers, but we can get the serial number through some of the parameters it belong, let's take a look at how to get and display the serial number calculation method as follows: (1) in the background DataGrid.currentPageIndex * DataGrid.pageSize e.Item.ItemIndex 1 (2) in the foreground DataGrid1.CurrentPageIndex * DataGrid1.PageSize Container.ItemIndex 1 Description: e System.Web.UI.WebControls.DataGridItemEventArgs shows an example of the parameter class; the DataGrid1 shows an example where the front DataGrid.currentPageIndex: Get or set the index of the current display page; DataGrid.pageSize: Get or set the number of items to display on the single page of the DataGrid control. Here I used four ways to display the serial number at the front desk, but it was expanded around the above calculation. (1) Use DataGrid's itemcreated settings, and the cell's cell can be a binding column or template column (including empty template); (2) using the DataGrid's itemDatabase value, and the front desk can be a binding column or Template column (including empty template); (3) Direct binding calculation expressions in front desk; (4) Calculate the expression by inheritance of the front page class in the background class. Remarks: Setting the extra number of serial numbers when you get data in the database, you don't discuss it, I think this is the worst implementation method.
Below to get the data of the Customers table of the Northwind database, the following: Sequence number 1 serial number 2 serial number 3 serial number 4 serial 5 Customerid 51 51 51 51 51 LoneP 52 52 52 52 52 MAGAA 53 53 53 53 53 Maisd 54 54 54 54 54 Merep 55 55 55 55 56 Norts 57 57 57 57 57 Ocean 58 58 58 58 59 59 Ottik 60 60 60 60 60 Paris 1 2 3 4 5 6 7 8 9 10 below is WebFormPaging .aspx file code, <% @ page language = "c #" codebehind = "WebFormPaging.aspx.cs" autoeventwireup = "false" inherits = "aspnetpaging.webform1"%> >