C#中实现数据库中数据分页显示的问题
请问如何不使用.net提供的控件,使用DataSet来实现将数据库中的数据分页显示呢?我现在有两个类:Employee类是对数据路中的employee表的映射。Emplo...
请问如何不使用.net提供的控件,使用DataSet来实现
将数据库中的数据分页显示呢?
我现在有两个类:
Employee类是对数据路中的employee表
的映射。
EmployeeDAO类是对Employee的操作--有增删改查
等方法。
有一窗体EmployeeForm.aspx运行时分页显示数据表中的内容。 展开
将数据库中的数据分页显示呢?
我现在有两个类:
Employee类是对数据路中的employee表
的映射。
EmployeeDAO类是对Employee的操作--有增删改查
等方法。
有一窗体EmployeeForm.aspx运行时分页显示数据表中的内容。 展开
1个回答
展开全部
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
private string m_sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("db.mdb");
int num;
protected void Page_Load(object sender, EventArgs e)
{
if(!this.IsPostBack)
{
Label1.Text = "1";
DataListDataBind();
}
}
private void DataListDataBind()
{
num = Convert.ToInt32(Label1.Text);
OleDbConnection con = new OleDbConnection(m_sConnectionString);
OleDbDataAdapter dr = new OleDbDataAdapter("select * from News", con);
DataSet ds = new DataSet();
dr.Fill(ds, "admin");
PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables["admin"].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 3;
ps.CurrentPageIndex = num - 1;
this.Button1.Enabled = true;
this.Button2.Enabled = true;
if (num == 1)
{
this.Button1.Enabled = false;
}
if (num == ps.PageCount)
{
this.Button2.Enabled = false;
}
Datalist1.DataSource = ps;
Datalist1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(Convert.ToInt32(Label1.Text) - 1);
DataListDataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(Convert.ToInt32(Label1.Text) + 1);
DataListDataBind();
}
}
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
private string m_sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("db.mdb");
int num;
protected void Page_Load(object sender, EventArgs e)
{
if(!this.IsPostBack)
{
Label1.Text = "1";
DataListDataBind();
}
}
private void DataListDataBind()
{
num = Convert.ToInt32(Label1.Text);
OleDbConnection con = new OleDbConnection(m_sConnectionString);
OleDbDataAdapter dr = new OleDbDataAdapter("select * from News", con);
DataSet ds = new DataSet();
dr.Fill(ds, "admin");
PagedDataSource ps = new PagedDataSource();
ps.DataSource = ds.Tables["admin"].DefaultView;
ps.AllowPaging = true;
ps.PageSize = 3;
ps.CurrentPageIndex = num - 1;
this.Button1.Enabled = true;
this.Button2.Enabled = true;
if (num == 1)
{
this.Button1.Enabled = false;
}
if (num == ps.PageCount)
{
this.Button2.Enabled = false;
}
Datalist1.DataSource = ps;
Datalist1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(Convert.ToInt32(Label1.Text) - 1);
DataListDataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(Convert.ToInt32(Label1.Text) + 1);
DataListDataBind();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |