遍历目录下所有图片文件显示的方法.(已废弃)

Posted on 2006-06-27 14:41  fgp3  阅读(382)  评论(0)    收藏  举报
  protected void Page_Init(object sender, EventArgs e)
    {
        this.Imgpre.ImageUrl = "../images/title/0.gif";

        string[] fileentries;
        fileentries = Directory.GetFiles(Server.MapPath("~/flyxnews/images/title"));
        int j = fileentries.Length;
        string[] filenames = new string[j];
        for (int i = 0; i < j; i++)
        {
            filenames[i] = Path.GetFileName(fileentries[i]);
        }
        for (int i = 0; i < j; i++)
        {
            this.Panelimgchoose.Controls.Add(imgchosse(filenames)[i]);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    //图片选择框函数
    public ImageButton[] imgchosse(string[] filenames)
    {
        int j = filenames.Length;
        ImageButton[] img = new ImageButton[j];
        for (int i = 0; i < j; i++)
        {
            string imgid = filenames[i].Replace(".gif", "");
            img[i] = new ImageButton();
            img[i].ID = imgid;
            img[i].ToolTip = "请点击选择";
            img[i].AlternateText = "尝试贴图,可耻地失败鸟";
            img[i].CssClass = "postimg";
            img[i].BorderStyle = BorderStyle.Outset;
            img[i].BorderWidth = 2;
            string imgurl = "../images/title/" + filenames[i];
            img[i].Height = 50;
            img[i].Width = 50;
            img[i].ImageUrl = imgurl;
            img[i].Click += new ImageClickEventHandler(this.imgs_Click);
        }
        return img;
    }
    protected void imgs_Click(object sender, ImageClickEventArgs e)
    {
        this.Imgpre.ImageUrl = ((ImageButton)sender).ImageUrl;
    }
}

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3