怎么样才能实现datalist的分页啊。我在咱们论坛发了很多次贴子了都没有解决请您能帮我修改代码,让它能实现分页,感谢,我为这个忙很久了
(piclist3.aspx)
<%@ Page Language="VB" Explicit="True" Debug="True"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Data"%>
<script runat="server">
 dim public cdir as string
Sub Page_Load(sender As Object, e As EventArgs)   
     Dim strpath As String    
     cdir = Request("dir")  If Not Page.IsPostBack  Then
    strPath = Request.Params("path")
    If strPath = "" Then
      strPath = "."
    End If
    strPath = ResolveURL(strPath)
    If Right(strPath,1) <> "/" Then
      strPath = strPath & "/"
    End If
    lblPath.Text = strPath
    DisplayFolder()       
  End If  if cdir <> "" then         
     lblpath.text = cdir
     DisplayFolder()
  end if  
  
End SubSub DisplayFolder()
  Dim strPath As String
  Dim dnfCur As DirectoryInfo
  Dim dtbDirs As DataTable
  Dim dnfSub As DirectoryInfo
  Dim rowPix As DataRow
  Dim dtbPix As DataTable
  Dim clmPix As DataColumn
  Dim fnfCur As FileInfo
  Dim strExt As String
  Dim dvwPix As DataView
  strPath = lblPath.Text  dnfCur = New DirectoryInfo(server.mappath(strPath))
  dtbDirs = new DataTable("sublist")
  dtbDirs.Columns.Add("DirName", _
       System.Type.GetType("System.String"))  For each dnfSub in dnfCur.GetDirectories
    If left(dnfSub.Name,1) <> "_" Then
      rowPix = dtbDirs.NewRow()
      rowPix("DirName") = dnfSub.Name
      dtbDirs.Rows.Add(rowPix)
    End If
  Next  repDirs.DataSource = dtbDirs
  repDirs.DataBind
  dtbPix = new DataTable("dirlist")
  clmPix = dtbPix.Columns.Add("FileLocn", _
           System.Type.GetType("System.String"))
  clmPix = dtbPix.Columns.Add("FileThum", _
           System.Type.GetType("System.String"))   For Each fnfCur In dnfCur.GetFiles("*.*")
    strExt = Lcase(fnfCur.Extension)
    If left(strExt,1) = "." Then
      strExt = mid(strExt,2)
    End If
    If (strExt = "gif") _
    Or (strExt = "jpg") _
    Or (strExt = "jpeg") _
    Or (strExt = "bmp") Then
      rowPix = dtbPix.NewRow()      
      rowPix("FileLocn") = strPath & fnfCur.Name
      rowPix("FileThum") =  "picture.aspx?" & _
             "size=120&url=" & strPath & fnfCur.Name
      dtbPix.Rows.Add(rowPix)
    End If
  Next   repPix.DataSource = dtbpix
  repPix.DataBind()
 upload_file.InnerHtml="<a href=upload_file2.aspx?dir=" & lblpath.text & ">上传文件</a>"
End SubSub repDirsCmd(source As Object, _
               e As RepeaterCommandEventArgs)
  If e.CommandArgument = ".." Then
    If lblPath.Text <> "/" Then
     
      lblPath.Text = Left(lblPath.Text, _
                     InStrRev(lblPath.text, "/", _
                     len(lblPath.text) - 1))
    End If
  else
    lblPath.Text = _
      ResolveURL(lblPath.Text & e.CommandArgument & "/")
   End If
  DisplayFolder()
End Sub</script>
<html>
<head>
<title>Select Thumbnail</title>
<link rel="stylesheet" type="text/css" href="normal.css">
<link rel="stylesheet" type="text/css" href="small.css">
</head>
<body>
 <asp:label id="lblPath" runat="server" />
<hr align="left" noshade>
<form method="POST" style="margin:0" runat="server">
<table border="1" cellpadding="8" cellspacing="0">
<tr><td>
  <asp:Repeater id="repDirs" onItemCommand="repDirsCmd" runat="server"> <headertemplate> 
    <table border="0" cellspacing="0">
      <tr> 
        <td> <asp:ImageButton id="IbtUp"
                  ImageUrl="folder-up.gif"
                  CommandArgument=".."
                  width="17" height="15" runat="server" /> </td>
        <td>(parent)</td>
      </tr></headertemplate >
      <itemtemplate> 
        <tr> 
          <td> 
            <asp:ImageButton id="IbtSubFld"
                 ImageUrl="folder-open.gif"
                 CommandArgument='<%# Container.DataItem("DirName")%>'
                 runat="server" /></td>
          <td><%# Container.DataItem("DirName")%> </td>
        </tr>
      </itemtemplate>
      <footertemplate>     </table>
      </footertemplate>
   </asp:repeater>    
</td>
<td><span id="upload_file" runat="Server"/></td>
<td><span id="up_dir" runat="Server"/></td>  
</tr>
</table>     
</form>
<hr  noshade  height="1" align="left">
<asp:DataList id="repPix" runat="server"
           BorderColor="black"
           CellPadding="10"
           Font-Name="Verdana"
           Font-Size="8pt"
           border="1"
           RepeatDirection="Horizontal"
           RepeatColumns="4">
         <HeaderStyle BackColor="#999999">
         </HeaderStyle>
         <ItemStyle BackColor="Gainsboro" 
          HorizontalAlign="center" 
          VerticalAlign="middle">              
         </ItemStyle>
         <HeaderTemplate>
            Items
         </HeaderTemplate>              
         <ItemTemplate >
<table><tr><td align="center">
            <a target="main" align="center"
        href="showpic.aspx?pic=<%# 
                    Container.DataItem("FileLocn") %>">
      <img align="center" src="<%# Container.DataItem("FileThum") %>"
        border="0"></a>
</td></tr></table>
         </ItemTemplate> 
      </asp:DataList> 
</body>
</html>

解决方案 »

  1.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=47DD34FD-ED0B-4455-94E8-CD9F63E19893
      

  2.   

    <% @ Page Language="C#" %>
    <% @ Import Namespace="System.Data" %>
    <% @ Import Namespace="System.Data.OleDb" %>
    <Script Language="C#" Runat="Server">
    /*
        Create By 飞刀
        http://www.aspcn.com
        2001-7-25 01:44    Support .Net Framework Beta 2
    */
    OleDbConnection MyConn;
    int PageSize,RecordCount,PageCount,CurrentPage;
    public void Page_Load(Object src,EventArgs e)
    {
        //设定PageSize
        PageSize = 10;
        
        //连接语句
        string MyConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+Server.MapPath(".")+"..\\DataBase\\db1.mdb;";
        MyConn = new OleDbConnection(MyConnString);
        MyConn.Open();    //第一次请求执行
        if(!Page.IsPostBack)
        {
            ListBind();
            CurrentPage = 0;
            ViewState["PageIndex"] = 0;        //计算总共有多少记录
            RecordCount = CalculateRecord();
            lblRecordCount.Text = RecordCount.ToString();        //计算总共有多少页
            PageCount = RecordCount/PageSize;
            lblPageCount.Text = PageCount.ToString();
            ViewState["PageCount"] = PageCount;
        }
    }
    //计算总共有多少条记录
    public int CalculateRecord()
    {
        int intCount;
        string strCount = "select count(*) as co from Score";
        OleDbCommand MyComm = new OleDbCommand(strCount,MyConn);
        OleDbDataReader dr = MyComm.ExecuteReader();
        if(dr.Read())
        {
            intCount = Int32.Parse(dr["co"].ToString());
        }
        else
        {
            intCount = 0;
        }
        dr.Close();
        return intCount;
    }ICollection CreateSource()
    {
        
        int StartIndex;
        
        //设定导入的起终地址
        StartIndex    = CurrentPage*PageSize;
        string strSel = "select * from Score";
        DataSet ds = new DataSet();    OleDbDataAdapter MyAdapter = new OleDbDataAdapter(strSel,MyConn);
        MyAdapter.Fill(ds,StartIndex,PageSize,"Score");
        
        return ds.Tables["Score"].DefaultView;
    }
    public void ListBind()
    {
        score.DataSource = CreateSource();
        score.DataBind();
        
        lbnNextPage.Enabled = true;
        lbnPrevPage.Enabled = true;
        if(CurrentPage==(PageCount-1)) lbnNextPage.Enabled = false;
        if(CurrentPage==0) lbnPrevPage.Enabled = false;
        lblCurrentPage.Text = (CurrentPage+1).ToString();}public void Page_OnClick(Object sender,CommandEventArgs e)
    {
        CurrentPage = (int)ViewState["PageIndex"];
        PageCount    = (int)ViewState["PageCount"];    string cmd = e.CommandName;
        //判断cmd,以判定翻页方向
        switch(cmd)
        {
            case "next":
                if(CurrentPage<(PageCount-1)) CurrentPage++;
                break;
            case "prev":
                if(CurrentPage>0) CurrentPage--;
                break;
        }    ViewState["PageIndex"] = CurrentPage;    ListBind();
        
    }
    </script>
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <form runat="server">
    共有<asp:Label id="lblRecordCount" ForeColor="red" runat="server" />条记录&nbsp;    
    当前为<asp:Label id="lblCurrentPage" ForeColor="red" runat="server" />/<asp:Label id="lblPageCount" ForeColor="red" runat="server" />页&nbsp;<asp:DataList id="score" runat="server"
    HeaderStyle-BackColor="#aaaadd"
    AlternatingItemStyle-BackColor="Gainsboro"
    EditItemStyle-BackColor="yellow"
    >
        <ItemTemplate>
            姓名:<%# DataBinder.Eval(Container.DataItem,"Name") %>
            <asp:LinkButton id="btnSelect" Text="编辑" CommandName="edit" runat="server" />
        </ItemTemplate>
    </asp:DataList>
    <asp:LinkButton id="lbnPrevPage" Text="上一页" CommandName="prev" OnCommand="Page_OnClick" runat="server" />
    <asp:LinkButton id="lbnNextPage" Text="下一页" CommandName="next" OnCommand="Page_OnClick" runat="server" /></form>
    </body>
    </html>
      

  3.   

    参考--Paging in DataList:
    http://aspalliance.com/articleViewer.aspx?aId=157&pId=
      

  4.   

    把图片存入数据库,然后用DATALIST调用绑定并进行分页