随机图像我想显示随机图像显示在运行时
继承人我的代码
private void Page_Load(object sender, EventArgs e)
{
int num1=0;
Random randNum = new Random();
num1 = randNum.Next(0, 9);
Image1.ImageUrl = DisplayNumber(num1);
Image1.Visible=true;
}
protected string DisplayNumber(int i)
{
string imagepath="";
switch (i)
{
case 0:
imagepath = "~/fordoctor/doctor_login/images/0.GIF";
break;
case 1:
imagepath = "~/fordoctor/doctor_login/images/1.GIF";
break;
case 2:
imagepath = "~/fordoctor/doctor_login/images/2.GIF";
break;
case 3:
imagepath = "~/fordoctor/doctor_login/images/3.GIF";
break;
case 4:
imagepath = "~/fordoctor/doctor_login/images/4.GIF";
break;
case 5:
imagepath = "~/fordoctor/doctor_login/images/5.GIF";
break;
case 6:
imagepath = "~/fordoctor/doctor_login/images/6.GIF";
break;
case 7:
imagepath = "~/fordoctor/doctor_login/images/7.GIF";
break;
case 8:
imagepath = "~/fordoctor/doctor_login/images/8.GIF";
break;
case 9:
imagepath = "~/fordoctor/doctor_login/images/9.GIF";
break;
}
Session["num1"] = imagepath;
return imagepath;
}
,但它不显示任何 我甚至已经检查使用的Response.Write(会话[“NUM1”图像]的ToString()); 和图像显示在下一页
考虑 的ImagePath =的String.Format( “〜/ fordoctor/doctor_login /图片/ {0} .gif注意”,我); 摆脱开关/案例 – 2009-05-18 07:09:31
感谢您的一个很好的建议 – Searock 2009-05-18 07:17:41