我需要一点点帮助。 一个前同事做了这个,它工作正常,但我需要图像是可点击链接,并使其在弹出窗口中以完整大小显示。 我是C#的新手,我真的可以使用一些帮助。
这里是代码
Asp.net
<div id="album">
<asp:DropDownList ID="albumDrop" runat="server" Width="150px">
</asp:DropDownList>
<br />
<asp:Button ID="albumbtn" runat="server" Text="Vælg album" OnClick="albumbtn_Click" />
</div>
<div id="albumContent">
<asp:Label ID="albumContentlbl" runat="server" Text="" ></asp:Label>
</div>
</div>
C#代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class galleri : System.Web.UI.Page
{
string[] albums;
protected void Page_Load(object sender, EventArgs e)
{
opdaterAlbums();
}
public void opdaterAlbums()
{
albums = Directory.GetDirectories(Server.MapPath("~/Uploads/"));
if (albumDrop.Items.Count == 0)
{
for (int i = 0; i < albums.Count(); i++)
{
string[] billede = albums[i].Split('\\');
albumDrop.Items.Add(billede[billede.Count() - 1]);
}
}
}
protected void albumbtn_Click(object sender, EventArgs e)
{
string[] billeder = Directory.GetFiles(Server.MapPath("~/Uploads/" + albumDrop.SelectedValue));
for (int i = 0; i < billeder.Count(); i++)
{
string[] billede = billeder[i].Split('\\');
Image img = new Image();
img.Width = 200;
img.Height = 200;
img.CssClass = "image";
img.ImageUrl = billede[billede.Count() - 3] + "/" + billede[billede.Count() - 2] + "/" + billede[billede.Count() - 1];
albumContentlbl.Controls.Add(img);
}
}
}
管理员页面(图片上传)
protected void UploadFile(object sender, EventArgs e)
{
if(albumNavntxt.Text != "")
{
string album = albumNavntxt.Text;
string path = Server.MapPath("~/Uploads/" + album);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(path + "/" + fileName);
Response.Redirect(Request.Url.AbsoluteUri);
billedeError.Text = "Billedet er uploaded!";
billedeError.ForeColor = System.Drawing.Color.Green;
billedeError.Visible = true;
}
else
{
billedeError.Text = "Begge felter skal være udfyldt!";
billedeError.ForeColor = System.Drawing.Color.Red;
billedeError.Visible = true;
}
}