是高手就进来 求问怎么把文本文件内容读取出来按条件查询好分页显示到页面上!!!(用三层架构的) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 说的不明不白,可以将文本组织成xml,webservice传递,这样方便你查询,用LinQ查询方便 如果你的txt文件 一行代表一条数据 那就简单多了 先读出来 然后存储 然后条件筛选 然后分页。 我是读取出来了,以List存储最重要的就是分页问题 一种是用xml,读到DataSet里;另一种用TextFile,用OleDb for .net操作,可以用sql语句。 分页用AspNetPager控件就行了,很简单。 研究老半天,研究不出来所以来求救了,我是把数据都读出来了,现在我用了Repeater来显示,我是想用分页控件进行每页显示10条记录。。以前我用的数据库这样就行了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)+aspnetpageraspnetpager你可以查看下官方的API或范例 很简单的 配置下 然后给aspnetpager 设置总记录数 以及 每页显示条数 就OK拉。 如何判断验证码,在线等。。 windows Mobile 上怎么用wmp做在线播放呢? 问高手一个动态生成控件的问题 联动控件及ascx问题,在线等!!! DataGrid的排序问题 ===江湖救急呀,怎么把参数传给现有的页面=== XP系统下IIS如何浏览网站? 急~~菜鸟一个~~请各位大哥大姐帮帮忙~~~~ 取消html中img的属性 大家好 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拉。