在aspx文件已经实现了DL的分页.
考虑到页面代码太多,所以想通过调用类方法来实现 da.Fill(ds, AspNetPager.PageSize * (AspNetPager.CurrentPageIndex - 1), AspNetPager.PageSize, "dlbd");这句代码在类里该怎么写呢using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.SqlClient;public partial class Fenye_Datalist : System.Web.UI.Page
{
protected Myclass m = new Myclass();
protected SqlConnection conn;
protected string connstring = ConfigurationManager.AppSettings["constr"];
protected void Open()
{
if (conn == null)
{
conn = new SqlConnection(connstring);
}
if (conn.State.Equals(ConnectionState.Closed))
{
conn.Open();
}
} public void Close()
{
if (conn != null)
conn.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
AspNetPager.PageSize = 5;
AspNetPager.AlwaysShow = true;
if (!IsPostBack)
{
AspNetPager.RecordCount = count();
ddbind();
}
}
private void ddbind()
{
Open();
SqlDataAdapter da = new SqlDataAdapter("select * from dlbd", conn);
DataSet ds = new DataSet();
da.Fill(ds, AspNetPager.PageSize * (AspNetPager.CurrentPageIndex - 1), AspNetPager.PageSize, "dlbd");
DataList1.DataSource = ds.Tables["dlbd"];
DataList1.DataBind(); Label1.Text = "记录总数:<font color=\"blue\"><b>" + AspNetPager.RecordCount.ToString() + "</b></font>";
Label1.Text += " 总页数:<font color=\"blue\"><b>" + AspNetPager.PageCount.ToString() + "</b></font>";
Label1.Text += " 当前页:<font color=\"red\"><b>" + AspNetPager.CurrentPageIndex.ToString() + "";
} protected void AspNetPager_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
{
AspNetPager.CurrentPageIndex = e.NewPageIndex;
ddbind();
}
public int count()
{
string sql = "select count(*) from dlbd";
int c = m.Sql_ScanReturn(sql);
return c;
}
}
考虑到页面代码太多,所以想通过调用类方法来实现 da.Fill(ds, AspNetPager.PageSize * (AspNetPager.CurrentPageIndex - 1), AspNetPager.PageSize, "dlbd");这句代码在类里该怎么写呢using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.SqlClient;public partial class Fenye_Datalist : System.Web.UI.Page
{
protected Myclass m = new Myclass();
protected SqlConnection conn;
protected string connstring = ConfigurationManager.AppSettings["constr"];
protected void Open()
{
if (conn == null)
{
conn = new SqlConnection(connstring);
}
if (conn.State.Equals(ConnectionState.Closed))
{
conn.Open();
}
} public void Close()
{
if (conn != null)
conn.Close();
}
protected void Page_Load(object sender, EventArgs e)
{
AspNetPager.PageSize = 5;
AspNetPager.AlwaysShow = true;
if (!IsPostBack)
{
AspNetPager.RecordCount = count();
ddbind();
}
}
private void ddbind()
{
Open();
SqlDataAdapter da = new SqlDataAdapter("select * from dlbd", conn);
DataSet ds = new DataSet();
da.Fill(ds, AspNetPager.PageSize * (AspNetPager.CurrentPageIndex - 1), AspNetPager.PageSize, "dlbd");
DataList1.DataSource = ds.Tables["dlbd"];
DataList1.DataBind(); Label1.Text = "记录总数:<font color=\"blue\"><b>" + AspNetPager.RecordCount.ToString() + "</b></font>";
Label1.Text += " 总页数:<font color=\"blue\"><b>" + AspNetPager.PageCount.ToString() + "</b></font>";
Label1.Text += " 当前页:<font color=\"red\"><b>" + AspNetPager.CurrentPageIndex.ToString() + "";
} protected void AspNetPager_PageChanged(object src, Wuqi.Webdiyer.PageChangedEventArgs e)
{
AspNetPager.CurrentPageIndex = e.NewPageIndex;
ddbind();
}
public int count()
{
string sql = "select count(*) from dlbd";
int c = m.Sql_ScanReturn(sql);
return c;
}
}
其实类随便写,关键是方法,你的方法用几个参数把所需要的对象传递过来,这不就解决问题了?