我有一個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