我想把AspNetPager与DataList结合使用.但是只做了一部分就不会了,哪位高手能指教?
1、页面代码如下:
<asp:DataList ID="DataList1" runat="server"  RepeatDirection="Horizontal" RepeatColumns="2" Width="100%">
        <ItemStyle Width="50%"/>
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,"title")%>&nbsp;&nbsp;&nbsp;&nbsp;
<hr>
</ItemTemplate>
        </asp:DataList>
    <webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Center" onpagechanged="AspNetPager1_PageChanged"
        width="100%"></webdiyer:aspnetpager>
2、后台代码如下:
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
           bindData();
        }
    }    void bindData()
    {
        string sql1 = "select top 8 * from info  order by hits,id desc";
        OleDbDataAdapter da1 = new OleDbDataAdapter(sql1, my_conn);
        DataSet ds1 = new DataSet();
        da1.Fill(ds1, "info");
        this.DataList1.DataSource = ds1.Tables["info"].DefaultView;
        this.DataList1.DataBind();
        
    }
接下来还要怎么做才能实现最终效果?谢谢!!

解决方案 »

  1.   

    分我拿走
    AspNetPager用法你拿走
      

  2.   

    地址在这
    http://www.cnblogs.com/wennxxin/archive/2008/10/16/1312954.html
      

  3.   

    AspNetPager有个事件好像叫PageChanging()、你可以写个分页存储过程、当点击AspNetPager那个事件后、重新绑定DataList、这样就可以了、AspNetPager自带生成存储过程的功能、你看下
      

  4.   

     参考
    http://www.cnblogs.com/ly5201314/archive/2008/09/09/1287450.html
    http://download.csdn.net/sort/tag/AspNetPager
    http://download.csdn.net/source/134663
    http://download.csdn.net/source/386421
      

  5.   

    翻页事件怎么写?
     protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            
            bindData();
        }
      

  6.   

    <webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize=10
    Font-Size="9pt" Font-Names="宋体" FirstPageText="首页" LastPageText="尾页" 
    NextPageText="下一页" PageIndexBoxType="TextBox" PrevPageText="上一页" 
    ShowPageIndexBox="Always" SubmitButtonText="跳转" TextAfterPageIndexBox="页" 
    TextBeforePageIndexBox="转到" ShowNavigationToolTip="True" CenterCurrentPageButton="True">
    </webdiyer:AspNetPager> Private Function GetBindData(ByVal getMax As Boolean) As DataSet
            Dim lnkSqlConnStr As String = System.Configuration.ConfigurationManager.ConnectionStrings("LocalSqlServer").ToString().Trim()
            Dim conn As SqlConnection = New SqlConnection(lnkSqlConnStr)
            conn.Open()
            Try
                Dim styleId As String = ""
                Dim keyword As String = ""            styleId = Request.QueryString("styleId")
                keyword = IIf(Request.QueryString("keyword") = Nothing, "", Request.QueryString("keyword"))            Dim tmpDataTable As New DataTable()
                Dim doSql As String            doSql = "select * from Hotel where IsDele=0 "            If keyword.Trim() <> "" Then
                    doSql += " and Name like '%" & keyword & "%'"
                End If            doSql += " order by Id"
                Dim myset As DataSet = New DataSet()
                Dim myadp As SqlDataAdapter = New SqlDataAdapter(doSql, conn)
                If getMax = True Then
                    myadp.Fill(myset, "rntable")
                Else
                    myadp.Fill(myset, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "rntable")
                End If            Return myset        Catch ex As Exception
                conn.Close()
                Return Nothing
            Finally
                conn.Close()
            End Try
        End Function
        Private Sub DoBind()
            Try
                Dim tmpSet As DataSet = New DataSet()
                tmpSet = GetBindData(False)
                If Not tmpSet Is Nothing Then
                    Me.DataListAttractionsDisp.DataKeyField = "Id"           '定义主键
                    Me.DataListAttractionsDisp.DataSource = tmpSet.Tables(0)
                    Me.DataListAttractionsDisp.DataBind()
                End If
            Catch ex As Exception        End Try
        End Sub
        Protected Sub AspNetPager1_PageChanging(ByVal src As Object, ByVal e As Wuqi.Webdiyer.PageChangingEventArgs) Handles AspNetPager1.PageChanging
            AspNetPager1.CurrentPageIndex = e.NewPageIndex
            GetBindData(False)
            DoBind()
        End Sub