我有6個問題在6 asp.net面板服務器控制, 我需要以隨機順序一個接一個地顯示它們(一個問題是可見的,每次看不到)。在asp.net中的非重複隨機數C#
我不知道如何排除再次產生的數字。 我寫這樣的:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Random rnd = new Random();
int startNumber = rnd.Next(1, 6);
ShowNextPanel(startNumber);
}
}
private void ShowNextPanel(int excludeNumber)
{
Random rnd = new Random();
//I need to exclude the "excludeNumber" here but I don't know how !?
int number = rnd.Next(1, 6);
switch (number)
{
case 1:
{
Panel1.Visible = true;
break;
}
case 2:
{
Panel2.Visible = true;
break;
}
case 3:
{
Panel3.Visible = true;
break;
}
case 4:
{
Panel4.Visible = true;
break;
}
case 5:
{
Panel5.Visible = true;
break;
}
case 6:
{
Panel6.Visible = true;
break;
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
// InsertToDB(1, DropDownList1.SelectedValue);
Panel1.Visible = false;
ShowNextPanel(1);
}
protected void Button2_Click(object sender, EventArgs e)
{
// InsertToDB(2, DropDownList2.SelectedValue);
Panel2.Visible = false;
ShowNextPanel(2);
}
//and go on till button6_click
我想要的只是展示每個問題一次,我需要以隨機的方式一一展示。 – Mostafa 2011-05-27 17:34:30