(1)在后台
DataGrid.CurrentPageIndex * DataGrid.PageSize + e.Item.ItemIndex + 1
(2)在前台
DataGrid1.CurrentPageIndex * DataGrid1.PageSize + Container.ItemIndex + 1
说明:
e表示System.Web.UI.WebControls.DataGridItemEventArgs参数类的实例;
DataGrid1这里表示前台的一个实例;
DataGrid.CurrentPageIndex:获取或设置当前显示页的索引;
DataGrid.PageSize :获取或设置要在 DataGrid 控件的单页上显示的项数。
下面我使用了4种方法来在前台显示序号,不过都是围绕上面的计算式展开。
(1) 使用DataGrid的ItemCreated设置值,而前台的单元格可以是绑定列或者模板列(包括空模板);
(2) 使用DataGrid的ItemDataBound设置值,而前台的单元格可以是绑定列或者模板列(包括空模板);
(3) 在前台直接绑定计算表达式;
(4) 在后台类中编写方法计算表达式由前台页面类继承调用。
备注:在数据库中获取数据时设置额外的序号列这里不做讨论,我认为这是最糟糕的实现方法。
下面以获取Northwind数据库的Customers表的数据为列,显示如下:
序号1
序号2
序号3
序号4
序号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
55
MORGK
56
56
56
56
56
NORTS
57
57
57
57
57
OCEAN
58
58
58
58
58
OLDWO
59
59
59
59
59
OTTIK
60
60
60
60
60
PARIS
1 2 3 4 5 6 7 8 9 10
下面是WebFormPaging.ASPx文件代码,
WebForm1
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/1697933/viewspace-897060/,如需转载,请注明出处,否则将追究法律责任。

<%=items[i].content%>
<%if(items[i].items.items.length) { %><%=items[i].items.items[j].username%> 回复 <%=items[i].items.items[j].tousername%>: <%=items[i].items.items[j].content%>
最新文章
- oracle中怎样将字段建成象SQL2000中的ID自动+1的字段
- Cannot resolve collation conflict for equal to operation
- Speed Up SQL Server Apps -提高SQL Server应用程序的运行效率
- Five Ways to Rev up Your SQL Performance
- SQL SERVER – 检测LOCK、终止会话 ID/UOW 的用户进程
- DBCC DBREINDEX重建索引提高SQL Server性能
- The Effect of NOLOCK on Performance
- The SQL Server 2005 XML Temptress
- Locking
- sp_lock
转载于:http://blog.itpub.net/1697933/viewspace-897060/