谁能告诉我如何使用 datapager 实现自定义分页。现在我已经设法用 2 个按钮(用于下一页和上一页)和 LoadListview() 方法来做到这一点,但我想在 datapager 中使用这个方法。有什么建议么?
文件后面的代码:
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BusinessConnectionString"].ToString());
SqlDataAdapter adap;
int startIndex;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadListview();
}
}
private void LoadListview()
{
string FindWhat = Request.QueryString["Find"];
string FindWhere = Request.QueryString["Where"];
string TownName = FindWhere;
string CountyName = FindWhere;
string PostcodeName = FindWhere;
//startIndex = int.Parse(ViewState["index"].ToString());
startIndex = MyDataPager.StartRowIndex * MyDataPager.PageSize;
int endIndex = startIndex + MyDataPager.PageSize;
adap = new SqlDataAdapter("SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY id_Business) AS MyRow, id_Business, Name, TownName FROM UbeloView WHERE (Name Like '%" + FindWhat + "%' AND TownName Like '%" + TownName + "%') UNION ALL SELECT ROW_NUMBER() OVER (ORDER BY id_Business) AS MyRow, id_Business, Name, TownName FROM UbeloView WHERE (Name Like '%" + FindWhat + "%' AND CountyName Like '%" + CountyName + "%') UNION ALL SELECT ROW_NUMBER() OVER (ORDER BY id_Business) AS MyRow, id_Business, Name, TownName FROM UbeloView WHERE (Name Like '%" + FindWhat + "%' AND PostcodeName Like '%" + PostcodeName + "%')) AS log WHERE MyRow >=" + startIndex + " AND MyRow <=" + endIndex + " ", conn);
DataSet ds = new DataSet();
adap.Fill(ds);
lstBusiness.DataSource = ds;
lstBusiness.DataBind();
}
protected void MyDataPager_PreRender(object sender, EventArgs e)
{
LoadListview();
}