List<T>的一个数据分页,对分页数据有帮助
2012-03-15 13:58
363 查看
protected void Page_Load(object sender, EventArgs e)
{
int intPageRow = 6;//每页中的数据条数
//有分页的现象
List<MyFriend> lst = new List<MyFriend>();
for (int m = 0; m < 13; m++)
{
MyFriend t = new MyFriend();
t.IntRows = m;
t.UserName = System.DateTime.Now.ToString()+"_"+m.ToString();
lst.Add(t);
}
int intCount = lst.Count;
int intPageCount;//分页页数
//intPageRow为每页的数据数目
if (intCount % intPageRow == 0)
{
intPageCount = intCount / intPageRow;
}
else
{
intPageCount = intCount / intPageRow + 1;
}
string[] arr = new string[intPageCount];
for (int k = 0; k < intPageCount; k++)
{
int intBeginRecord = intPageRow*k;
int intEndRecord = intPageRow * (k + 1);//要提取的记录数目
if (intEndRecord > intCount)
{
intEndRecord = intCount;
}
string strID = "";
string strUserName = "";
string[] arrCurrentPageData = new string[intPageRow];
List<MyFriend> lstE = new List<MyFriend>();
for (int m = intBeginRecord; m < intEndRecord; m++)
{
//得到该页的数据
MyFriend tC = new MyFriend();
tC.IntRows = lst[m].IntRows;
tC.UserName = lst[m].UserName;
lstE.Add(tC);
}
//这里可以将该List 处理你的业务逻辑 对lstE处理
}
}
//
//构造List
private class MyFriend
{
private int intRows;
private string userName;
public int IntRows
{
set { intRows = value; }
get { return intRows; }
}
public string UserName
{
set { userName = value; }
get { return userName; }
}
}
{
int intPageRow = 6;//每页中的数据条数
//有分页的现象
List<MyFriend> lst = new List<MyFriend>();
for (int m = 0; m < 13; m++)
{
MyFriend t = new MyFriend();
t.IntRows = m;
t.UserName = System.DateTime.Now.ToString()+"_"+m.ToString();
lst.Add(t);
}
int intCount = lst.Count;
int intPageCount;//分页页数
//intPageRow为每页的数据数目
if (intCount % intPageRow == 0)
{
intPageCount = intCount / intPageRow;
}
else
{
intPageCount = intCount / intPageRow + 1;
}
string[] arr = new string[intPageCount];
for (int k = 0; k < intPageCount; k++)
{
int intBeginRecord = intPageRow*k;
int intEndRecord = intPageRow * (k + 1);//要提取的记录数目
if (intEndRecord > intCount)
{
intEndRecord = intCount;
}
string strID = "";
string strUserName = "";
string[] arrCurrentPageData = new string[intPageRow];
List<MyFriend> lstE = new List<MyFriend>();
for (int m = intBeginRecord; m < intEndRecord; m++)
{
//得到该页的数据
MyFriend tC = new MyFriend();
tC.IntRows = lst[m].IntRows;
tC.UserName = lst[m].UserName;
lstE.Add(tC);
}
//这里可以将该List 处理你的业务逻辑 对lstE处理
}
}
//
//构造List
private class MyFriend
{
private int intRows;
private string userName;
public int IntRows
{
set { intRows = value; }
get { return intRows; }
}
public string UserName
{
set { userName = value; }
get { return userName; }
}
}
相关文章推荐
- MVC分页控件之二,为IQueryable定义一个扩展方法,直接反回PagedList<T>结果集(转)
- 【转载】MVC分页控件之二,为IQueryable定义一个扩展方法,直接反回PagedList<T>结果集
- 如何将一个List<Map<String,String>>类型的集合数据转换成json格式输出
- 将List<Map<String,String>型的数据,变成一个JSON对象。
- 当需要对一个list<Map<String,Object>>中的map添加一个相同的数据是可以参考
- 把一个List<String>集合中的数据用分隔符分开,并以字符串展示出来
- 用java读取一个文件往hbase里插入数据(List<PUT>)
- 把一个List<T>的数据复制至另一个List<T>
- MVC分页控件之二,为IQueryable定义一个扩展方法,直接反回PagedList<T>结果集
- Android本地最简单的数据存储,没有之一(让SharedPreferences存取JavaBean对象或List<Bean>)
- 判定一个list<int>中的元素和一个vector<int>中的元素是否相等
- 合并List<Map<String,String>>中的重复数据并对某个字段做累加
- C# List<T> Add方法循环添加时只保存了最后一次的数据(覆盖问题)
- 过滤掉List<HashMap<String,Object>>中键值相同的数据!
- Android保存List<Map<String,Object>>数据到SD卡及读取
- 将一个List<Object>转换成json,方便前台界面获取
- SqlQueryToList 执行SQL语句并把结果返回成一个List<dynamic>
- List<Map<String,Object>>集合根据map里面的一个字段排序
- List<T> 直接绑定到datagridview上不显示数据.
- 定义一个静态方法,该方法可以接收一个List<Integer>,方法内对List进行排序