久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

DataList,PageDataSource打造簡(jiǎn)單的相冊(cè)

 抓不住幸福 2010-11-10
我們一般可以使用 PageDataSource類來對(duì)Repeter,DataList等控件進(jìn)行分頁,。我們同樣也可以利用它來打造一個(gè)支持分頁的簡(jiǎn)單的相冊(cè)。
這個(gè)是頁面源碼,顯示圖片:
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div align="center">
            <asp:DataList ID="MainAlbum" runat="server" BackColor="#CCCCCC" BorderColor="#999999"
                BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" ForeColor="Black"
                GridLines="Both" RepeatColumns="4" RepeatDirection="Horizontal">
                <FooterStyle BackColor="#CCCCCC" />
                <SelectedItemStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                <ItemStyle BackColor="White" />
                <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                <ItemTemplate>
                <div>
                     <a href='<%#"Photos/"+Eval("Name") %>' target="_blank" />
                    <asp:Image ID="Image1" runat="server" width="200" Height="160" ImageUrl='<%#"Photos/"+Eval("Name") %>' />
                </div>                        
               </ItemTemplate>
            </asp:DataList></div>
            <div align="center">
                <asp:Label ID="lblPageCount" runat="server"></asp:Label>
                <asp:Label ID="lblCount" runat="server"></asp:Label>
                <asp:LinkButton ID="lbtnPreview" runat="server" Text="上一頁" OnClick="lbtnPreview_Click"></asp:LinkButton>
                <asp:LinkButton ID="lbtnNext" runat="server" Text="下一頁" OnClick="lbtnNext_Click"></asp:LinkButton>
            </div>
    </form>
顯示圖片的后臺(tái)代碼:
    protected void Page_Load(object sender, EventArgs e)
    ...{
        if (!IsPostBack)
        ...{
            lblCount.Text = "1";
            BindPhotos();
        }
    }
    private void BindPhotos()
    ...{
        //圖片路徑
        string ImagePath = Server.MapPath("~/Photos/");
        DirectoryInfo ImageFile = new DirectoryInfo(ImagePath);
        //得到目錄下的所有圖片
        FileInfo[] FileArray = ImageFile.GetFiles("*.jpg");
        DataTable dtPhoto = new DataTable("Album");
        DataColumn colSmall = new DataColumn("Name");
        DataColumn colNormal = new DataColumn("Photo");
        dtPhoto.Columns.Add(colSmall);
        dtPhoto.Columns.Add(colNormal);
        //將圖片存入tabele中
         for (int i = 0; i < (FileArray.Length); i++)
         ...{
             DataRow Row = dtPhoto.NewRow();
             Row["Name"] = FileArray[i].Name;
             Row["Photo"] = "./Photos/" + FileArray[i].Name;
             dtPhoto.Rows.Add(Row);
         }
        //這里就是分頁的代碼
        PagedDataSource Source = new PagedDataSource();
        Source.AllowPaging = true;
        Source.DataSource = dtPhoto.DefaultView;
        Source.PageSize = 12;
        int CurrentPage = Convert.ToInt32(lblCount.Text);
        Source.CurrentPageIndex = CurrentPage - 1;
        lbtnPreview.Enabled = true;
        lbtnNext.Enabled = true;
        if (CurrentPage == 1)
        ...{
            lbtnPreview.Enabled = false;
        }
        if (CurrentPage == Source.PageCount)
        ...{
            lbtnNext.Enabled = false;
        }
        lblPageCount.Text = "共"+Source.PageCount+"頁,當(dāng)前為";
        MainAlbum.DataSource = Source;
        //MainAlbum.DataSource = ImageFile.GetFiles("*.jpg");
        MainAlbum.DataBind();
       
    }
    //下一頁
    protected void lbtnNext_Click(object sender, EventArgs e)
    ...{
        lblCount.Text = Convert.ToString(Convert.ToInt32(lblCount.Text) + 1);
        BindPhotos();
    }
    //上一頁
    protected void lbtnPreview_Click(object sender, EventArgs e)
    ...{
        lblCount.Text = Convert.ToString(Convert.ToInt32(lblCount.Text) - 1);
        BindPhotos();
    }
批量上傳的代碼:
    protected void btnMultiple_Click(object sender, EventArgs e)
    ...{
        string FilePath = Server.MapPath("~/Photos/");
        HttpFileCollection UploadFile = Request.Files;
        if (FileUpload1.HasFile || FileUpload2.HasFile || FileUpload3.HasFile || FileUpload4.HasFile || FileUpload5.HasFile)
        ...{
            for (int i = 0; i < UploadFile.Count; i++)
            ...{
                HttpPostedFile PostFile = UploadFile[i];
                try
                ...{
                    if (PostFile.ContentLength > 0)
                    ...{
                        string FileNames = PostFile.FileName;
                        string SingleName = FileNames.Substring(FileNames.LastIndexOf("\") + 1);
                        PostFile.SaveAs(FilePath + SingleName);
                    }
                }
                catch (Exception ex)
                ...{
                    Assistant.AlertMessage(ex.Message, this);
                }
            }
            Response.Redirect("~/MainAlbum.aspx");
        }
        else
        ...{
            Assistant.AlertMessage("請(qǐng)輸入要上傳的文件", this);
        }
      
    }
本文來自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/oyjd614/archive/2007/11/18/1891282.aspx

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多