我现在正在做电子商务网站,我想用DataList来显示商品信息。但是我的数据很的多,可能一页还显示不完,怎么设置DataList来分页显示。因为DataList排版布局数据信息很好,不想用DataGrid。请楼上的告诉偶!~!

解决方案 »

  1.   

    google一下 DataList 分页,很多的
      

  2.   

    用DataApdater.Fill(DataSet,startrow,rowcount,name)来实现啊
      

  3.   

    不会吧!~!
      就这样简单一句话啊
        请楼上的高手说详细点好吗?
    到什么google里搜索,那我也知道做,但是现在网络信息有很多垃圾,而且也很浪费时间。
      

  4.   

    datalist分页跟电子商务有什么关系的吗?
    自已写分页SQL命令, 自己画分页导航条啊
      

  5.   

    要么用SQL分
    要么用DATASOUROBJECT
      

  6.   

    试试我写的这个免费分页控件:http://www.webdiyer.com
      

  7.   

    引用:chenxuchen()-用DataApdater.Fill(DataSet,startrow,rowcount,name)来实现啊我来简单介绍一下:
    DataSet 至你要填充的的DataSet 对象,startrow 填充起始行的索引,rowcount 要填充多少行,name DataSet 中的DataTable 表名。比方说 第一页 (每页10行)   DataApdater.Fill(ds,0,10,"Table")
           第二页              DataApdater.Fill(ds,10,10,"Table")
           第三页              DataApdater.Fill(ds,20,10,"Table")
           ......也可以用PagedDataSource 来实现分页。
      

  8.   

    推荐使用陕北吴旗娃的免费分页控件:http://www.webdiyer.com
      
     
      

  9.   

    <asp:datalist id="MyList" Runat="server" RepeatColumns="2">
    <ItemTemplate>
    <table border="0" width="300">
    <tr>
    <td width="25">&nbsp;</td>
    <td width="100" valign="middle" align="right">
    <a href='ProductDetails.aspx?ProductID=<%# DataBinder.Eval(Container.DataItem,"ProductID")%>'>
    <img src='manage/uploadpic/<%# DataBinder.Eval(Container.DataItem,"ProductImage")%>' width="75" height="75" border="0"></a></td>
    <td width="200" valign="middle"><a href='ProductDetails.aspx?ProductID=<%# DataBinder.Eval(Container.DataItem,"ProductID")%>'>
    <font color="#000000"><b>
    <%# DataBinder.Eval(Container.DataItem,"ModelName")%>
    </b></font>
    <br>
    </a><b>UnitCost:</b><%# DataBinder.Eval(Container.DataItem,"UnitCost","{0:c}")%><br>
    <a href='AddToCart.aspx?ProductID=<%# DataBinder.Eval(Container.DataItem,"ProductID")%>'>
    <img src="img/btnaddtocart.gif" border="0"></a></td>
    </tr>
    </table>
    </ItemTemplate>
    </asp:datalist>
    <table style="WIDTH: 708px; HEIGHT: 40px">
    <TR>
    <TD>Total Recored:
    <asp:label id="lblRecordCount" runat="server" ForeColor="red"></asp:label>&nbsp; 
    Total Page:
    <asp:label id="lblPageCount" runat="server" ForeColor="red"></asp:label>&nbsp; 
    Current Page:
    <asp:label id="lblCurrentPage" runat="server" ForeColor="red"></asp:label>&nbsp;
    </TD>
    <TD>
    <asp:imagebutton id="lbnPrevPage" runat="server" ImageUrl="img/btnprev.gif" OnCommand="Page_OnClick"
    CommandName="prev"></asp:imagebutton>
    <asp:imagebutton id="lbnNextPage" runat="server" ImageUrl="img/btnnext.gif" OnCommand="Page_OnClick"
    CommandName="next"></asp:imagebutton></TD>
    </TR>
    </table>
    后台代码:using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using System.Configuration;
    using ShopClass;namespace web
    {
    /// <summary>
    /// ProductsList 的摘要说明。
    /// </summary>
    public class ProductsList : System.Web.UI.Page
    {
    //SqlConnection MyConn;    
    int PageSize,RecordCount,PageCount,CurrentPage;  
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.DataList MyList;
    protected System.Web.UI.WebControls.Label lblRecordCount;
    protected System.Web.UI.WebControls.Label lblPageCount;
    protected System.Web.UI.WebControls.Label lblCurrentPage;
    protected System.Web.UI.WebControls.ImageButton lbnPrevPage;
    protected System.Web.UI.WebControls.ImageButton lbnNextPage; 
    protected ProductsDB PDB=new ProductsDB();

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    //设定PageSize    
    PageSize = 10;    
    //连接语句    
    //string MyConnString =  ConfigurationSettings.AppSettings["strConnection"];    
    //MyConn = new SqlConnection(MyConnString);
    //打开数据库连接  
    //MyConn.Open();  //第一次请求执行    
    if(!Page.IsPostBack)    
    {    
    Label1.Text="Products list:";
    //计算总共有多少记录    
    // RecordCount = CalculateRecord(); //同 CalculateRecord() 
    RecordCount=PDB.GetProductsCategoryCount(Int32.Parse(Request.Params["CategoryID"]));
    //计算总共有多少页  
    //取整    
    PageCount = RecordCount/PageSize;    
    if (RecordCount%PageSize > 0) 
    {
    PageCount = PageCount + 1;  
    }
    lblPageCount.Text = PageCount.ToString();    
    lblRecordCount.Text = RecordCount.ToString();  
    ViewState["PageCount"] = PageCount;  
    CurrentPage = 0;    
    ViewState["PageIndex"] = 0;    
    //绑定    
    ListBind();  
    }  }
    // 此处原本用于SQL语句分页,但后来采用存储过程,所以注掉!
    // 此处和ProductsDB.cs中GetProductsCategoryCount函数互斥!
    // public int CalculateRecord()    
    // {    
    // int intCount;    
    // string strCount = "select count(*) as co from Products where CategoryID="+Request.Params["CategoryID"];  
    // SqlCommand MyComm = new SqlCommand(strCount,MyConn);    
    // SqlDataReader dr = MyComm.ExecuteReader();    
    // if(dr.Read())    
    // {    
    // intCount = Int32.Parse(dr["co"].ToString());    
    // }    
    // else    
    // {    
    // intCount = 0;    
    // }    
    // dr.Close();    
    // return intCount;    
    // }   
    // 此处原本用于SQL语句分页,但后来采用存储过程,所以注掉!
    // 此处和ProductsDB.cs中GetProducts函数互斥!
    // ICollection CreateSource()    
    // {    
    //
    // //设定导入的起终地址    
    // int StartIndex = CurrentPage*PageSize;    
    // string strSel = "select * from Products where CategoryID="+Request.Params["CategoryID"];    
    // DataSet ds = new DataSet();    
    // SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,MyConn);    
    // MyAdapter.Fill(ds,StartIndex,PageSize,"fenye");    
    // return ds.Tables["fenye"].DefaultView;    
    // }     public void ListBind()    
    {    
    int StartIndex = CurrentPage*PageSize; 
    // MyList.DataSource=CreateSource();  //同 ICollection CreateSource()
    MyList.DataSource = PDB.GetProducts(Int32.Parse(Request.Params["CategoryID"]),StartIndex,PageSize,"fenye");    
    MyList.DataBind();  
      
    lbnNextPage.Enabled = true;    
    lbnPrevPage.Enabled = true;    
    if(PageCount==0)    
    {    
    lblCurrentPage.Text = "0";    
    lbnNextPage.Enabled = false;    
    lbnPrevPage.Enabled = false;    
    }    
    else    
    {    
    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();    
    }  
    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    }
    }
    你可以直接引用
      

  10.   

    Datalis分页和Repeater分页一样的,在CSDN搜一下很多这样的贴。且代码很详细