我試圖從數組中獲取2個獨特圖像。現在我刷新頁面,直到我得到2個獨特的圖像。這並不理想。我怎樣才能修改這段代碼來取回2個獨特的圖像,而無需刷新頁面,直到頁面出現爲止。從數組中返回2個隨機圖像
我可以在這一層做,或者我需要檢查數據層中的唯一號碼嗎?
Picture dlPicture = new Picture();
DataTable DTPictures = dlPicture.GetRandomPicture();
Picture dlPicture2 = new Picture();
DataTable DTPictures2 = dlPicture2.GetRandomPicture();
// the variables to hold the yes and no Id's for each set
string firstNoPicId = "";
string firstYesPicId = "";
string secondNoPicId = "";
string secondYesPicId = "";
foreach (DataRow row in DTPictures.Rows)
{
firstYesPicId = row["PicID"].ToString();
secondNoPicId = firstYesPicId;
FirstPicMemberNameLabel.Text = row["MemberName"].ToString();
FirstPicLink.ImageUrl = "Pictures/" + row["PicLoc"];
}
foreach (DataRow row in DTPictures2.Rows)
{
secondYesPicId = row["PicID"].ToString();
firstNoPicId = secondYesPicId;
SecondPicMemberNameLabel.Text = row["MemberName"].ToString();
SecondPicLink.ImageUrl = "Pictures/" + row["PicLoc"];
}
if (firstYesPicId != secondYesPicId)
{
FirstPicLink.PostBackUrl = "default.aspx?yesId=" + firstYesPicId + "&noId=" + firstNoPicId;
SecondPicLink.PostBackUrl = "default.aspx?yesId=" + secondYesPicId + "&noId=" + secondNoPicId;
}
else
{
Response.Redirect("Default.aspx");
}
哪裏的.GetRandomPicture()的代碼? – curtisk 2011-12-15 19:27:42
爲什麼`GetRandomPicture`返回一個`DataTable`爲什麼你循環它的行並一遍又一遍地設置相同的變量? – Magnus 2011-12-15 19:34:48
我在代碼中看不到任何東西。 – 2011-12-15 19:36:36