[c#]代码库
//查数据库使用Linq表达式
/// <summary>
/// 分页获取数据
/// </summary>
/// <param name="PageIndex"></param>
/// <param name="PageSize"></param>
/// <param name="total"></param>
/// <param name="DepartmentID"></param>
/// <returns></returns>
public static IList<c_operator> GetListPage(int PageIndex, int PageSize, out int total)
{
try
{
using (CertDataContext cdc = new CertDataContext(Tool.sqlstr))
{
total = cdc.c_operator.Count();
return cdc.c_operator.Skip(PageIndex * PageSize).Take(PageSize).ToList();
}
}
catch (Exception)
{
total = 0;
return null;
}
}
//GriedView绑定数据源
public void gvBind()
{
int count = 0;
this.GridView1.DataSource = DepartmentBLL.GetAll(Pager1.PageIndex, Pager1.PageSize, out count);
this.GridView1.DataBind();
Pager1.ItemCount = count;
if (count > Pager1.PageSize)
{
Pager1.Visible = true;
}
else
Pager1.Visible = false;
}
[代码运行效果截图]
[源代码打包下载]