隨機圖像我想顯示隨機圖像顯示在運行時
繼承人我的代碼
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