Several methods of displaying a DataGrid control column number in ASP.NET
Author: Zheng Zuo
2004-9-10
There are many controls in APS.NET, which should be DataGrid is the most complete, but it does not provide ready-to-digital display logs, but we can indirectly get the serial number through some of the parameters it. 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) at the front desk
DataGrid1.currentpageIndex * DataGrid1.pageSize Container.ItemIndex 1
Description:
e represents an instance of the system.web.ui.webcontrols.dataGriditeMeventArgs parameter class;
DataGrid1 here means an example of the front desk;
DataGrid.currentPageIndex: Get or set the index of the current display page;
DataGrid.pageSize: Gets or sets 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 the DataGrid's itemcreated settings, while the front desk can be a binding column or template column (including empty template);
(2) Use the DataGrid's itemDatabase value, while the front desk can be a binding column or template column (including empty template);
(3) Calculate the expression directly in the front desk;
(4) Calculation of the expression in the background class inheritance is called by the front page 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.
The following is to get the data of the Customers table of the Northwind database, as follows:
Below is the webformPaging.aspx file code,
<% @ Page language = "c #" codebehind = "WebFormPaging.aspx.cs" autoeventwireup = "false" inherits = "aspnetpaging.webform1"%>
3C
// DTD HTML 4.0 Transitional // En ">
head>