|
DataGrid dg = (DataGrid)sender;
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
e.Item.Cells[0].Text = (dg.CurrentPageIndex * dg.PageSize + e.Item.ItemIndex + 1).ToString();
e.Item.Cells[1].Text = (dg.CurrentPageIndex * dg.PageSize + e.Item.ItemIndex + 1).ToString();
}
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DataGrid dg = (DataGrid)sender;
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
((Label)e.Item.FindControl("itemIndex")).Text = (dg.CurrentPageIndex * dg.PageSize + e.Item.ItemIndex + 1).ToString();
}
}
}
}
数据层代码如下:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace AspnetPaging
{
public class DataAccess
{
private static string connString = ConfigurationSettings.AppSettings["ConnString"];
private DataAccess()
{
}
public static DataSet GetCustomersData()
{
SqlConnection conn = new SqlConnection(connString);
SqlCommand comm = new SqlCommand("GetCustomers",conn);
comm.CommandType = CommandType.StoredProcedure;
SqlDataAdapter dataAdapter = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
return ds;
}
}
}
总结,上面的四种方法前两种其实处理起来是一样的,只是处理的时间不同而已;对于第三种我认为最简单,直接在前台页面绑定,不需要额外的辅助;对于第四种的方法绑定到前台我认为最为灵活,需要注意的是GetRecordIndex方法需要protected或public,使它的继承类能访问的到。
上一页 [1] [2] [3] [4] [5] [C语言系列]NET 中C#的switch语句的语法 [系统软件]托拽Explore中的文件到VB.net的窗口 [系统软件]Boost库在XP+Visual C++.net中的安装 [常用软件]新配色面板:Paint.Net3.0RC1官方下载 [常用软件]用内建的“Net Meeting”聊天 [VB.NET程序]Henry的VB.NET之旅(三)—共享成员 [VB.NET程序]Henry的VB.NET之旅(二)—构造与析构 [VB.NET程序]Henry的VB.NET之旅(一)—失踪的窗体 [VB.NET程序]在托盘上显示Balloon Tooltip(VB.NET) [VB.NET程序]VB.NET中关于DataGrid颜色的自定义。
|