图片以3列形式显示      
<asp:DataList ID="myDataList" runat="server" RepeatColumns="3">
            <ItemTemplate>
                <table width="250px" height="200px" border="0px">
                    <tr>
                        <td align="center" ><a href="produce.aspx" target="_blank" >
                        <img src='images/ProductImages/<%#DataBinder.Eval(Container.DataItem, "Image")%>' width=250px height=180px  border="0"/></a>
                        </td>
                    </tr>
                    <tr>
                        <td align="center"><a href="ProductDetails.aspx" target="_blank">
                            <%#DataBinder.Eval(Container.DataItem, "Name")%></a>
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:DataList>
             <!--分页导航-->
        <table width="85%" height="28" border="0" cellpadding="0" cellspacing="0">
            <tr>
       
                <td align="right" valign="middle" class="c001">
                    <asp:HyperLink ID="lnkFirst" runat="server">[首 页]</asp:HyperLink>
                    <asp:HyperLink ID="lnkPrev" runat="server">[上一页]</asp:HyperLink>
                    <asp:HyperLink ID="lnkNext" runat="server">[下一页]</asp:HyperLink>
                    <asp:HyperLink ID="lnkLast" runat="server">[尾 页]</asp:HyperLink>
                </td>
            </tr>
        </table>   

  if (!this.IsPostBack)
            {
                string page = "";
                if ((Request.Params["Page"] != null) && (Request.Params["Page"].ToString() != ""))
                {
                    page = Request.Params["Page"];
                }


                BindData(page);
            }

        private void BindData(string page)
        {
            P_ProductBLL objproductBll = new P_ProductBLL();
            DataSet ds = objproductBll.GetAllList();
            PagedDataSource objpds = new PagedDataSource();
            objpds.DataSource = ds.Tables[0].DefaultView;
            int record_Count = ds.Tables[0].Rows.Count;
            int page_Size = 9;
            int totalPages = int.Parse(Math.Ceiling((double)record_Count / page_Size).ToString());

            int CurPage;
            if (page != "")
                CurPage = Convert.ToInt32(page);
            else
                CurPage = 1;
            objpds.AllowPaging = true;
            objpds.PageSize = page_Size;
            objpds.CurrentPageIndex = CurPage - 1;
            if (!objpds.IsFirstPage)
            {
                this.lnkFirst.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";
                lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
            }
            if (!objpds.IsLastPage)
            {
                lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
                this.lnkLast.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + totalPages.ToString();
            }
            myDataList.DataSource = objpds;
            myDataList.DataBind();
            //显示数量
            if (objpds.CurrentPageIndex == 0)
            {
                lnkFirst.Enabled = false;
                lnkPrev.Enabled = false;
                if (totalPages == 1)
                {
                    lnkLast.Enabled = false;
                    lnkNext.Enabled = false;
                }
            }
            else if (objpds.CurrentPageIndex == totalPages - 1)
            {
                lnkLast.Enabled = false;
                lnkNext.Enabled = false;
            }
        }

 

posted on 2008-01-10 16:27  yangyi.com  阅读(6523)  评论(1)    收藏  举报