DataTable dt = new DataTable();
if(Request.QueryString["typeId"] != null)
{
int typeId = Convert.ToInt32(Request.QueryString["typeId"]);
SqlParameter paramList = new SqlParameter("@pl_byProTypeId", SqlDbType.Int, 4);
paramList.Value = typeId;
using (SqlConnection connection = DataConnection.GetConnection())
{
dt = SQLHelper.ExecuteDataset(connection, CommandType.StoredProcedure, "proc_pro_select_proByTypeId", paramList).Tables[0];
}
}
else
{
using (SqlConnection connection = DataConnection.GetConnection())
{
dt = SQLHelper.ExecuteDataset(connection, CommandType.StoredProcedure, "proc_pro_select").Tables[0];
}
} ///分页代码
我设了一个datatable为公有的,然后用IF语句判断是否有产品类型ID传过来,来存储数据,然后再绑定到我的分页代码现在的问题是:
我首先访问了产品页面列出所有产品,产生了分页,然后我再点产品的类型,也产生了分页,当我点击类型的下一页,它不是连到同一类型的下一页,而是连去了所有产品的第二页这是什么问题呢?
解决方案 »
- treeview 单击事件怎么不能触发?
- 写一个返回DataSet的方法
- ListBox二级效果未实现...
- 调用淘宝公开API修改线上商品库存 提示 11Insufficient isv permissionsisv
- 大侠帮帮我!
- C# .NET Application使用问题
- 问一问:一个Master-Detail表单高手们都是怎么实现的?
- 急急急~~用VSS工具Chein的ASP.NET项目不能调试
- 页面之间如何传递数组和dataset????
- 能否给出编写控件的源码?控件有Button和TextBox合成
- asp.net 让图片自动适应 image控件的大小
- asp.net 邮件发送问题
{
get
{
return (int)ViewState["Page"];
}
set
{
ViewState["Page"] = value;
}
}
private void Databind(IList<LoginLog> dataSource,int count)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dataSource;
pds.AllowPaging = true;
pds.PageSize = 10;
pds.CurrentPageIndex = Index;
ViewState["allPage"] = pds.PageCount;
if (Index == 0)
{
this.imgPre.Visible = false;
this.imgFrist.Visible = false;
}
else if (Index == pds.PageCount - 1)
{
this.imgNext.Visible = false;
this.imgEnd.Visible = false;
}
if (count == 0)
{
this.lblCount.Text = "对不起,没有您要查询的记录!";
this.imgPre.Visible = false;
this.imgFrist.Visible = false;
this.imgNext.Visible = false;
this.imgEnd.Visible = false;
}
else if (count<=10)
{
this.lblCount.Text = "共 " + count + " 条数据 当前 " + (pds.CurrentPageIndex + 1) + "/" + pds.PageCount + " 页";
this.imgPre.Visible = false;
this.imgFrist.Visible = false;
this.imgNext.Visible = false;
this.imgEnd.Visible = false;
}
else
{
this.lblCount.Text = "共 " + count + " 条数据 当前 " + (pds.CurrentPageIndex + 1) + "/" + pds.PageCount + " 页";
}
this.GridView1.DataSource = pds;
this.GridView1.DataBind();
}
//加载事件
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["Page"] = 0;
Databind(LoginLogManager.FindAll(), LoginLogManager.CountALL());
}
}
//搜索按钮
protected void btnSearch_Click(object sender, EventArgs e)
{
Session["isClick"] = true;
string bTime = this.txtBeginTime.Text.Trim();
string eTime = this.txtEndTime.Text.Trim();
if (LoginLogManager.CountALLByTime(bTime, eTime) > 2)
{
this.imgNext.Visible = true;
this.imgEnd.Visible = true;
}
Databind(LoginLogManager.FindAllByTime(bTime, eTime), LoginLogManager.CountALLByTime(bTime, eTime));
}
//首页
protected void imgFrist_Click(object sender, ImageClickEventArgs e)
{
this.imgNext.Visible = true;
this.imgEnd.Visible = true;
ViewState["Page"] = 0;
if (Convert.ToBoolean(Session["isClick"]))
{
string bTime = this.txtBeginTime.Text.Trim();
string eTime = this.txtEndTime.Text.Trim();
Databind(LoginLogManager.FindAllByTime(bTime, eTime), LoginLogManager.CountALLByTime(bTime, eTime));
}
else
{
Databind(LoginLogManager.FindAll(), LoginLogManager.CountALL());
}
}
//上页
protected void imgPre_Click(object sender, ImageClickEventArgs e)
{
if (Index > 0)
{
this.imgNext.Visible = true;
this.imgEnd.Visible = true;
Index--;
}
if (Convert.ToBoolean(Session["isClick"]))
{
string bTime = this.txtBeginTime.Text.Trim();
string eTime = this.txtEndTime.Text.Trim();
Databind(LoginLogManager.FindAllByTime(bTime, eTime), LoginLogManager.CountALLByTime(bTime, eTime));
}
else
{
Databind(LoginLogManager.FindAll(), LoginLogManager.CountALL());
}
}
//下一页
protected void imgNext_Click(object sender, ImageClickEventArgs e)
{
if (Index >=0)
{
this.imgPre.Visible = true;
this.imgFrist.Visible = true;
Index++;
}
if (Convert.ToBoolean(Session["isClick"]))
{
string bTime = this.txtBeginTime.Text.Trim();
string eTime = this.txtEndTime.Text.Trim();
Databind(LoginLogManager.FindAllByTime(bTime, eTime), LoginLogManager.CountALLByTime(bTime, eTime));
}
else
{
Databind(LoginLogManager.FindAll(), LoginLogManager.CountALL());
}
} //末页
protected void imgEnd_Click(object sender, ImageClickEventArgs e)
{
this.imgPre.Visible = true;
this.imgFrist.Visible = true;
Index = Convert.ToInt32(ViewState["allPage"])-1; if (Convert.ToBoolean(Session["isClick"]))
{
string bTime = this.txtBeginTime.Text.Trim();
string eTime = this.txtEndTime.Text.Trim();
Databind(LoginLogManager.FindAllByTime(bTime, eTime), LoginLogManager.CountALLByTime(bTime, eTime));
}
else
{
Databind(LoginLogManager.FindAll(), LoginLogManager.CountALL());
}
} protected void btnGo_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(this.txtCount.Text)<=1)
{
Index = 0;
this.imgNext.Visible = true;
this.imgEnd.Visible = true;
}
else if (Convert.ToInt32(this.txtCount.Text) > Convert.ToInt32(ViewState["allPage"]) - 1)
{
Index = Convert.ToInt32(ViewState["allPage"]) - 1;
this.imgPre.Visible = true;
this.imgFrist.Visible = true;
}
else
{
Index = Convert.ToInt32(this.txtCount.Text) - 1;
this.imgNext.Visible = true;
this.imgEnd.Visible = true;
this.imgPre.Visible = true;
this.imgFrist.Visible = true;
}
Databind(LoginLogManager.FindAll(), LoginLogManager.CountALL());
}
既然你的产品类别是靠QueryString保持的,那么你就要看看你使用的所谓分页机制(特别是当你使用第三方控件时)是否搞丢了这个url参数。
先谢谢你了!你看看我这问题是不是这样造成的因为我是用Request.QueryString["typeId"] != null 来判断是否有值传过来
如果有值我就用该值来做查询条件,再列出对应的产品
没有值的就直接列出所有产品第一次加载的时候肯定是列出所有产品的,然后我再点左边的类型,是列出对应的产品,当我点击下一页的时候,因为我页面有刷新,所以造成Request.QueryString["typeId"] 这个值丢失了,就造成了下一页的内容变回了第一次加载时(也就是所有产品)第二页的内容,我觉得问题好像是这样了。另外请问你有学习asp.net2.0的网址吗!网上的教程很乱,会盲目学习的。谢谢!