第一次加载时显示正确的数据
可是当变换数据源的时候,数据库空间能显示正常的数据,而分页空间仍然是第一次加载时的情形(没有变化)代码如下:
public string xe = "";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
protected void Bind()
{
Repeater1.DataSource = DAL.producttype.TypeoneList();
Repeater1.DataBind();
Repeater1.AutoUpdateAfterCallBack = true;
if(xe=="yes")
{
int num = Convert.ToInt32(DBUtility.DbHelperOleDb.GetSingle("select count(uid) from Product where [Pistop]=1 and [Ptype]=" + Convert.ToInt32(ViewState["type"].ToString())).ToString());
AspNetPager1.RecordCount = num;
DataList1.DataSource = DAL.product.Product_istop_type(1, Convert.ToInt32(ViewState["type"].ToString()), this.AspNetPager1.PageSize * (this.AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize);
DataList1.DataBind();
DataList1.AutoUpdateAfterCallBack = true;
return;
}
int count = Convert.ToInt32(DBUtility.DbHelperOleDb.GetSingle("select count(uid) from Product where [Pistop]=1").ToString());
AspNetPager1.RecordCount = count;
DataList1.DataSource = DAL.product.Product_istop(1, this.AspNetPager1.PageSize * (this.AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize);
DataList1.DataBind();
DataList1.AutoUpdateAfterCallBack = true;
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
Bind();
}
/// <summary>
/// 搜索产品
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
if (Txt_key.Text.Trim().ToString() == "")
{
Anthem.Manager.AddScriptForClientSideEval("alert('您输入的产品名为空!')");
return;
}
int count = Convert.ToInt32(DBUtility.DbHelperOleDb.GetSingle("select count(uid) from [Product] where [Pistop]=1 and [Pname] like '%" + Txt_key.Text.Trim() + "%'"));
if (count > 0)
{
Txt_key.Text = "";
Txt_key.AutoUpdateAfterCallBack = true;
DataList1.DataSource = DBUtility.DbHelperOleDb.Query("select * from [product] where [Pistop]=1 and [Pname] like '%" + Txt_key.Text.Trim() + "%' ORDER BY [UID] desc");
DataList1.DataBind();
DataList1.AutoUpdateAfterCallBack = true;
return;
}
Anthem.Manager.AddScriptForClientSideEval("alert('不存在该产品,或者输入过于复杂!')");
Txt_key.Text = "";
Txt_key.AutoUpdateAfterCallBack = true;
Bind();
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "choose")
{
xe = "yes";
ViewState["type"] = Convert.ToInt32(e.CommandArgument.ToString());
Bind();
}
}
敬请赐教!!!
我也遇到过 一般这个问题 都出现 要检查 (!IsPostBack)
不是多了就是少了,或者逻辑不对