DataList分页问题
上代码:数据绑定成功了 就是一直都是显示第一页内容 “首页 上一页 下一页 末页 跳转 ”功能都没有一个实现的 这是为什么求高手看看
private string myConn = ConfigurationManager.ConnectionStrings["ClientsConnectionString"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Bind(0);
}
//创建一个分页数据源的对象且一定要声明为静态
protected static PagedDataSource ps = new PagedDataSource();
private void Bind(int CurrentPage)
{
string selectSql = "select ClientID,ClientName,AddressStr,Email from OrderClient where ClientID<=700";
SqlConnection connectiong = new SqlConnection(myConn);
SqlDataAdapter da = new SqlDataAdapter(selectSql, connectiong);
DataSet ds = new DataSet();
da.Fill(ds, "OrderClient");
DataList1.DataSource = ds;
DataList1.DataBind();
ps.DataSource = ds.Tables["OrderClient"].DefaultView;
ps.AllowPaging = true;//是否可以分页
ps.PageSize = 4;
ps.CurrentPageIndex = CurrentPage;//取得当前页码
DataList1.DataSource = ps;
DataList1.DataKeyField = "ClientID";
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
switch (e.CommandName)
{
//以下5种情况分别为捕获用户点击第一页、上一页、下一页、最后一页和页面跳转是发生的事件
case "first":
ps.CurrentPageIndex = 0;
Bind(ps.CurrentPageIndex);
break;
case "pre":
ps.CurrentPageIndex = ps.CurrentPageIndex - 1;
Bind(ps.CurrentPageIndex);
break;
case "next":
ps.CurrentPageIndex = ps.CurrentPageIndex + 1;
Bind(ps.CurrentPageIndex);
break;
case "last":
ps.CurrentPageIndex = ps.PageCount - 1;
Bind(ps.CurrentPageIndex);
break;
case "search":
if (e.Item.ItemType == ListItemType.Footer)
{
int PageCount = int.Parse(ps.PageCount.ToString());
TextBox txtPage = e.Item.FindControl("txtPage") as TextBox;
int myPageNum = 0;
if (!txtPage.Text.Equals(""))
{
myPageNum = Convert.ToInt32(txtPage.Text.ToString());
if (myPageNum <= 0 || myPageNum > PageCount)
Response.Write("<script>alert('输入页数没有超出页数总数')</script>");
else
Bind(myPageNum - 1);
}
}
break;
}
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
//得到脚模板中的控件。并创建变量
Label CurrentPage = e.Item.FindControl("lblNowPage") as Label;
Label PageCount = e.Item.FindControl("lblCount") as Label;
LinkButton FirstPage = e.Item.FindControl("lnkbtnFirst") as LinkButton;
LinkButton PrePage = e.Item.FindControl("lnkbtnFont") as LinkButton;
LinkButton NextPage = e.Item.FindControl("lnkbtnNext") as LinkButton;
LinkButton LastPage = e.Item.FindControl("lnkbtnLast") as LinkButton;
CurrentPage.Text = (ps.CurrentPageIndex + 1).ToString();//绑定显示当前页
PageCount.Text = ps.PageCount.ToString();//绑定显示总页数
if (ps.IsFirstPage)
{
FirstPage.Enabled = false;
PrePage.Enabled = false;
}
if (ps.IsLastPage)
{
NextPage.Enabled = false;
LastPage.Enabled = false;
}
}
}
...全文
相关推荐
DataList控件的分页显示
使用PagedDataSource类实现DataList控件的分页显示
datalist分页技术及实现
datalist分页技术及实现,解决了许多,分页难以解决的问题,及更加灵活控制
datalist分页操作
本代码是datalist分页操作,主要功能能有上一页、下一页、首页、尾页等,并且有详细的数据绑定,并附有数据库!
asp.net里的DataList分页
DataList分页功能 1 2 3 4 5 点到页面分页标签变色
datalist 分页 数据库连接配置在wen.config
datalist 分页 数据库连接配置在wen.config .net+Mysql环境



