当前位置:编程学习 > C#/ASP.NET >>

asp.net datalist控件分页显示

如题~~~asp.net datalist控件如何实现分页显示,每页显示3条数据 --------------------编程问答-------------------- 在分也绑定的代码里面写
 PagedDataSource pds=new PagedDataSource();
 pds.AllowPaging = true;
 pds.PageSize = 3;
--------------------编程问答-------------------- 前台HTML:

<div style="width: 310px">
              共<a><%=totalPage %></a>页第<a class="number current"><%=currtPage%></a>页
              <asp:LinkButton ID="lnkBtn_First" runat="server" Text="首页" OnClick="lnkBtn_First_Click" ForeColor="Lime"></asp:LinkButton>
              <asp:LinkButton ID="lnkBtn_Prev" onmouseover="this.className='number current'" onmouseout="this.className='number'"
               runat="server" Text="上页" CssClass="number" OnClick="lnkBtn_Prev_Click" ForeColor="Lime"></asp:LinkButton>
              <asp:LinkButton ID="lnkBtn_Next" runat="server" Text="下页" OnClick="lnkBtn_Next_Click" ForeColor="Lime"></asp:LinkButton>
              <asp:LinkButton ID="lnkBtn_Last" onmouseover="this.className='number current'" onmouseout="this.className='number'"
               runat="server" CssClass="number" Text="尾页" OnClick="lnkBtn_Last_Click" ForeColor="Lime"></asp:LinkButton>
              转<asp:DropDownList ID="ddl_Page" width="35px" runat="server" 
              AutoPostBack="True" OnSelectedIndexChanged="ddl_Page_SelectedIndexChanged">
              </asp:DropDownList>页 
       </div>
--------------------编程问答-------------------- 后台cs:
分页绑定数据自己写,也为不知道你的数据库关系

//第一页
        protected void lnkBtn_First_Click(object sender, EventArgs e)
        {
            if (1 == currtPage)
            {
                return;
            }
            currtPage = 1;
            BindDataList();
        }

        //最后一页
        protected void lnkBtn_Last_Click(object sender, EventArgs e)
        {
            if (currtPage == totalPage)
            {
                return;
            }
            currtPage = totalPage;
            BindDataList();
        }

        //下一页
        protected void lnkBtn_Next_Click(object sender, EventArgs e)
        {
            if (currtPage + 1 > totalPage)
            {
                Response.Write("<script language=javascript>" + "alert(\"已经是最后一页\")" + "</script>");
                return;
            }
            currtPage += 1;
            BindDataList();
        }
        //上一页

        protected void lnkBtn_Prev_Click(object sender, EventArgs e)
        {
            if (0 == currtPage - 1)
            {
                Response.Write("<script language=javascript>" + "alert(\"已经是最后一页\")" + "</script>");
                return;
            }
            currtPage -= 1;
            BindDataList();
        }

        //跳页
        protected void ddl_Page_SelectedIndexChanged(object sender, EventArgs e)
        {
            currtPage = int.Parse(((DropDownList)sender).Text);
            BindDataList();
        }
--------------------编程问答-------------------- 试试AspNetPager: http://www.webdiyer.com/controls/aspnetpager --------------------编程问答-------------------- 对还不如aspnetpager灵活。。 --------------------编程问答-------------------- AspNetPager可以,也可以自定义分页的方式(例如:存储过程分页) --------------------编程问答--------------------
引用 4 楼  的回复:
试试AspNetPager: http://www.webdiyer.com/controls/aspnetpager


支持 顶个
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,