我页面里面有个datalist控件,和一个objectdatasourse,我自己写了个类,有个方法
public PagedDataSource getware()
{
string strcon = ConfigurationManager.ConnectionStrings["SuperMarketDBConnectionString"].ConnectionString;
string str = "select * from T_Ware";
SqlConnection con=new SqlConnection ();
con.ConnectionString =strcon ;
SqlDataAdapter sda = new SqlDataAdapter(str, con);
DataSet ds = new DataSet();
sda.Fill(ds, "Ware");
PagedDataSource pds= new PagedDataSource();
pds.DataSource = ds.Tables["Ware"].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 6;
return pds;
}这个方法给了objectdatasourse,我数据库里面有14条数据,这么说有3页,我datalist里面也编辑模版了,绑定了某些列,我界面还有2个按钮,怎么实现上一页,和下一页啊
public PagedDataSource getware()
{
string strcon = ConfigurationManager.ConnectionStrings["SuperMarketDBConnectionString"].ConnectionString;
string str = "select * from T_Ware";
SqlConnection con=new SqlConnection ();
con.ConnectionString =strcon ;
SqlDataAdapter sda = new SqlDataAdapter(str, con);
DataSet ds = new DataSet();
sda.Fill(ds, "Ware");
PagedDataSource pds= new PagedDataSource();
pds.DataSource = ds.Tables["Ware"].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 6;
return pds;
}这个方法给了objectdatasourse,我数据库里面有14条数据,这么说有3页,我datalist里面也编辑模版了,绑定了某些列,我界面还有2个按钮,怎么实现上一页,和下一页啊
解决方案 »
- 求一个浮动窗口,搜索了半天没有适合的,多谢。
- .NET怎么实现动态数组
- 同志们,大家帮忙啊!小弟又来提问了,关于asp.net中的javascript。
- 麻烦知道Blog的人讲解下什么是Blog?
- 求指点:一个的自己感觉良好的框架,该如何优化?
- 下载 PETSHOP 安装后,用VS打开时候 提示 无法创建打开应用程序,然后是 web(不可用)
- 请问Server.MapPath("WebForm1.aspx")这一句是什么意思啊?
- 关于asp.net2.0下用户重登陆的问题
- GridView的一些问题
- 参数传递问题?
- ASP.NET 调用存储过程问题
- 【求救大召唤】:在VS上调试没问题,但放到IIS上就崩坏了
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Class1 cs = new Class1();
PagedDataSource pds = cs.getware();
Labeltotal.Text = "共" + pds.PageCount + "页";
Labelcurrent.Text = "当前第" + ((pds.CurrentPageIndex) + 1).ToString() + "页";
ViewState["currentpage"] = 1;
} }
protected void LinkButton3_Click(object sender, EventArgs e)
{
Class1 cs = new Class1();
PagedDataSource pds = cs.getware();
if (1 !=(int )ViewState["currentpage"])
{
pds.CurrentPageIndex = (int)ViewState["currentpage"] - 2; }
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
Class1 cs = new Class1();
PagedDataSource pds = cs.getware();
if (pds.PageCount != (int)ViewState["currentpage"])
{
pds.CurrentPageIndex = (int)ViewState["currentpage"] ;
}
}
这是我的代码
ps.AllowPaging = true;
中间省略了数据库的操作
ps.PageSize = 5;
ps.CurrentPageIndex = currentPage - 1; LinkButtonTop.Enabled = true;
LinkButtonPrev.Enabled = true;
LinkButtonNext.Enabled = true;
LinkButtonLast.Enabled = true; if (currentPage == 1)
{
LinkButtonTop.Enabled = false;
LinkButtonPrev.Enabled = false;
}
if (currentPage == ps.PageCount)
{
LinkButtonNext.Enabled = false;
LinkButtonLast.Enabled = false; }
LabelCount.Text = Convert.ToString(ps.PageCount);//这是显用总页数的label
this.DataList1.DataSource = ps;
this.DataList1.DataBind(); }
上面的代码是数据绑定函数里面.
protected void LinkButtonPrev_Click(object sender, EventArgs e)
{
LabelNowPage.Text = Convert.ToString(Convert.ToInt32(LabelNowPage.Text) - 1);
this.dlbind();
}//这个就是实现上一页的函数
我这是有首页,上一页,下一页,尾页四个
不知道能看得懂不?