我有一个DataList来显示吨的项目,所以我使用分页和搜索方法,以便过滤和使它更容易,两者都工作正常。然而,搜索后,当涉及到传呼,数据将回(SELECT *),但没有具体的项目IM搜索DataList分页与搜索结果
是我迄今所做的:
SqlDataAdapter adap;
DataSet ds;
PagedDataSource adsource;
int pos;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.ViewState["vs"] = 0;
pos = (int)this.ViewState["vs"];
databind();
databind2();
}
}
public void databind()
{
adap = new SqlDataAdapter("select p.item_code as pitem, i.LongDesc as longname, p.SellPrice_1 as normalprice, p.SellPrice_2 as memberprice from plu p inner join item i on p.item_code = i.item_code WHERE p.publish =1 order by i.LongDesc", constr);
ds = new DataSet();
adsource = new PagedDataSource();
adap.Fill(ds);
adsource.DataSource = ds.Tables[0].DefaultView;
adsource.PageSize = 16;
adsource.AllowPaging = true;
adsource.CurrentPageIndex = pos;
CategoryList.DataSource = adsource;
CategoryList.DataBind();
}
滤波部分,如下所示
public void Filter_Command(Object source, DataListCommandEventArgs e)
{
if (e.CommandName.Equals("Filter"))
{
adap = new SqlDataAdapter("select p.item_code as pitem, i.LongDesc as longname, p.SellPrice_1 as normalprice, p.SellPrice_2 as memberprice, d.department_code as dcode, d.category_code as dcatecode, c.category_code as ccode from plu p inner join item i on p.item_code = i.item_code inner join EPO_PDU_department d on d.department_code = i.department_code inner join EPO_PDU_Category c on c.category_code = d.category_code WHERE p.publish =1 AND c.category_code = '" + e.CommandArgument.ToString() + "'order by i.LongDesc ", constr);
ds = new DataSet();
adsource = new PagedDataSource();
adap.Fill(ds);
adsource.DataSource = ds.Tables[0].DefaultView;
adsource.PageSize = 16;
adsource.AllowPaging = true;
adsource.CurrentPageIndex = pos;
btnprevious.Enabled = !adsource.IsFirstPage;
btnnext.Enabled = !adsource.IsLastPage;
CategoryList.DataSource = adsource;
CategoryList.DataBind();
}
}
按钮,我用:
protected void btnprevious_Click(object sender, EventArgs e)
{
pos = (int)this.ViewState["vs"];
pos -= 1;
this.ViewState["vs"] = pos;
databind();
}
protected void btnnext_Click(object sender, EventArgs e)
{
pos = (int)this.ViewState["vs"];
pos += 1;
this.ViewState["vs"] = pos;
databind();
}
搜索和呼叫正在没有彼此罚款。但我希望他们一起工作。感谢
******* UPDATE *******
按钮单击后你绑定未过滤的数据'databind()' – Rik
我注意到,但我不知道该如何修复该问题 – TheButterfly
让你的数据绑定应用过滤器(如果有的话) – Rik