我试图从数组中获取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