日期:2014-05-18  浏览次数:20464 次

求教,请各位帮忙
今天在使用ASPNETPAGER时,出现一个问题,我使用datalist绑定数据,ASPNETPAGER分页,我在用户控件里做,可以实现分页功能,我一把这个控件拖到设计页面时,测试就发现,aspnetpager不能使用了,只显示下页和尾页,而且点击没有作用,
前台代码:
HTML code
<div style="width:87%">
        <asp:DataList ID="dlNewsList" runat="server" Width="642px">
            <ItemTemplate>
              <table border="0" cellspacing="0" cellpadding="0" style="line-height:14px; width: 90%;">
                  <tr>
                    <td align="left" style="padding-left:20px; height: 22px;text-decoration:none">&middot;
                    <a href='NewDetail_ce.aspx?id=<%# Eval("id") %>' style="color:#686865">
                    <asp:Label ID="lblTitle"  runat="server" Text='<%# Eval("title") %>'></asp:Label></a></td>
                    <td style="height: 13px; width: 70px;">
                    [<asp:Label ID="lblPubDate" runat="server" Text='<%# GetDate(Eval("RELEASE_TIME").ToString()) %>'></asp:Label>]</td>
                  </tr>
                </table>
            </ItemTemplate>
        </asp:DataList>
        </div>
      <div style="text-align: center">
          <table border="0" cellpadding="0" cellspacing="0" align="center">
              <tr>
                  <td >
                      <webdiyer:AspNetPager ID="anpNews" runat="server" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页" ShowPageIndex="false" OnPageChanged="anpNews_PageChanged" PageSize="10"> </webdiyer:AspNetPager></td>
                  <td >
                      <asp:Label ID="lblCurrentPage" runat="server"></asp:Label></td>
              </tr>
          </table>
      </div>

后台代码:
C# code
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindNews();
        }
    }
     //<summary>
     //截取时间字符串,获取年月日
     //</summary>
     //<param name="date"></param>
    protected string GetDate(string date)
    {
        return date;
    }
    /// <summary>
    /// 获取新闻列表
    /// </summary>
    public void BindNews()
    {
        DataTable ds = DBHelper.GetDataSet("select * from News where type='xw' order by id desc");
        PagedDataSource pds = new PagedDataSource();
        anpNews.RecordCount = ds.DefaultView.Count;
        pds.DataSource = ds.DefaultView;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = anpNews.CurrentPageIndex - 1;
        pds.PageSize = anpNews.PageSize;
        lblCurrentPage.Text = "&nbsp;共" + pds.PageCount.ToString() + "页";
        this.dlNewsList.DataSource = pds;
        this.dlNewsList.DataBind();
        ds.Dispose();
    }
    /// <summary>
    /// 实现分页
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void anpNews_PageChanged(object sender, EventArgs e)
    {
        BindNews();
    }

,请各位帮个忙,谢了!

------解决方案--------------------
protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
{
AspNetPager1.