求问怎么把文本文件内容读取出来按条件查询好分页显示到页面上!!!(用三层架构的)
解决方案 »
- CheckBoxList
- js脚本和母版页的路径问题
- access 数据库升级时候,出现“语法错误 (操作符丢失) 在查询表达式”
- 求助:用window.showModalDialog时,ASP.NET中子窗口如何操作传递过来的window.dialogArguments(JS)这个值!!!!
- 为何我的程序用IIS不能浏览?高分求救
- 利用身份模拟技术模拟的管理员权限和添加到本地管理员组的权限有区别吗?什么区别?
- ASP.NET怎么实现 定时 发送邮件?急!!!!!!!!
- 数据库文件导出到excel文件问题?
- 帮忙看这句SQL,是不是漏洞很严重?谢谢
- 哪有crystal reports9.0(水晶报表)下载
- asp.net 调用 delphi 写的 dll 报错, 请高人指点
- easyui的datagrid的编辑器combobox数据源问题
我是读取出来了,以List存储最重要的就是分页问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyPerson.IDAL;
using MyPerson.Model;
using Person.DBUtility;
using System.Data.SqlClient;namespace MyPerson.SQLServerDAL
{
class News: INews
{
/// <summary>
/// 获取新闻列表
/// </summary>
/// <param name="pageSize">页面大小</param>
/// <param name="pageIndex">页码</param>
/// <param name="recordCount">所有记录数</param>
/// <param name="wheresql">条件语句例如 and newstitle='aaa' </param>
/// <param name="topCount">前面行</param>
/// <returns>返回新闻列表</returns>
public List<NewsInfo> GetAllNews(int? pageSize, int? pageIndex, ref int recordCount, string wheresql, int topCount)
{
List<NewsInfo> list = new List<NewsInfo>();
pageSize = pageSize ?? 10;
pageIndex = pageIndex ?? 1;
string sql = string.Format("select count(*) from (select top {0} * from news where 1=1 {1}) a", topCount, wheresql);
recordCount = (int)SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringProfile, System.Data.CommandType.Text, sql, null);
sql = string.Format("select top " + (pageSize * pageIndex).ToString() + " * from (select top {0} * from news where 1=1 {1}) a",topCount,wheresql);
sql += " except ";
sql += string.Format("select top " + (pageSize * (pageIndex - 1)).ToString() + " * from (select top {0} * from news where 1=1 {1}) a", topCount, wheresql);
using (SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringProfile, System.Data.CommandType.Text, sql, null))
{
while (dr.Read())
{
NewsInfo newsInfo = new NewsInfo();
newsInfo.NewsId = dr.GetInt32(0);
newsInfo.NewsTitle = dr.GetString(1);
newsInfo.NewsDate = dr.GetDateTime(2);
newsInfo.NewsContent = dr.GetString(4);
newsInfo.NewsMemo = dr.GetString(6);
newsInfo.NewsSort = dr.GetInt32(7);
if (newsInfo.NewsSort==1)
{
newsInfo.NewsSortName = "职场话题";
}
else if (newsInfo.NewsSort == 2)
{
newsInfo.NewsSortName = "职场气象";
}
list.Add(newsInfo);
}
}
return list;
}
}
}
如果你只是简单的想对数据集进行分页
你可以采用gridview(Repeater)+aspnetpager
aspnetpager你可以查看下官方的API或范例
很简单的 配置下 然后给aspnetpager 设置总记录数 以及 每页显示条数 就OK拉。