我已经尝试了几天来显示随机图像,但没有成功。代码旋转文件夹中的图像< / images> ,但始终显示源位置,请看这里:
下面你会找到我一直在玩的代码。感谢您的合作.. :)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace asp34_CasinoMegaChallenge
{
public partial class asp34 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GetFiles();
}
public string GetFiles()
{
Random random = new Random();
string[] randomImages=Directory.GetFiles(HttpContext.Current.Server.MapPath("~/Images/"));
Image1.ImageUrl = randomImages[random.Next(randomImages.Length)];
return Image1.ImageUrl;
}
}
}