您的位置:首页 > 其它

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

2006-06-27 14:41 671 查看
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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: