请教大家,我有个随机的问题,我刚在学.net程序,有下到一个源码,就是随机抽取考卷的,下面是随机的,但是我想把随机改成不随机的,按输入考题的顺序排列,该怎么样呢?谁能解答下:下面是部分代码,请问要改哪些?
tx_extime.Value = Kminfo[3];
string lst = roandow_data(mySet.Tables[0].Rows.Count, int.Parse(Kminfo[1]));
txID.Text = lst;
txVuale.Text = Kminfo[2];
string[] lsts=lst.Split(';');
for (int i=0;i<lsts.Length;i++)
{
Table ntb = new Table();
TD1.Controls.Add(ntb);
TableRow ntr = new TableRow();
ntb.Controls.Add(ntr);
TableCell ntc = new TableCell();
ntr.Controls.Add(ntc);
Label nlb = new Label();
nlb.Font.Bold = true;
nlb.Font.Size = 11;
nlb.Text = (i+1).ToString() + "、" + mySet.Tables[0].Rows[int.Parse(lsts[i])]["q_question"].ToString();
ntc.Controls.Add(nlb);
ntr = new TableRow();
ntb.Controls.Add(ntr);
ntc = new TableCell();
ntr.Controls.Add(ntc);
RadioButtonList nrbl = new RadioButtonList();
for (char ia = 'A'; ia <= 'D'; ia++)
{
ListItem li = new ListItem();
li.Text = ia.ToString() + "、" + mySet.Tables[0].Rows[int.Parse(lsts[i])]["q_key" + ia.ToString()].ToString();
li.Value = ia.ToString();
nrbl.Items.Add(li);
}
nrbl.ID = "q_" + mySet.Tables[0].Rows[int.Parse(lsts[i])]["q_id"].ToString();
ntc.Controls.Add(nrbl);
}
Button1.Visible = true;
}
private string roandow_data(int allcount, int thecount)
{
Random rnd = new Random();
List<int> lst = new List<int>();
int i = 0;
string str = "";
while (i < thecount)
{
int j = rnd.Next(allcount);
if (lst.IndexOf(j) == -1)
{
lst.Add(j);
i++;
}
}
foreach (int j in lst)
{
if (str.Length == 0)
{
str = j.ToString();
}
else
{
str = str + ";" + j.ToString();
}
}
return str;哪位能够解答下!!
tx_extime.Value = Kminfo[3];
string lst = roandow_data(mySet.Tables[0].Rows.Count, int.Parse(Kminfo[1]));
txID.Text = lst;
txVuale.Text = Kminfo[2];
string[] lsts=lst.Split(';');
for (int i=0;i<lsts.Length;i++)
{
Table ntb = new Table();
TD1.Controls.Add(ntb);
TableRow ntr = new TableRow();
ntb.Controls.Add(ntr);
TableCell ntc = new TableCell();
ntr.Controls.Add(ntc);
Label nlb = new Label();
nlb.Font.Bold = true;
nlb.Font.Size = 11;
nlb.Text = (i+1).ToString() + "、" + mySet.Tables[0].Rows[int.Parse(lsts[i])]["q_question"].ToString();
ntc.Controls.Add(nlb);
ntr = new TableRow();
ntb.Controls.Add(ntr);
ntc = new TableCell();
ntr.Controls.Add(ntc);
RadioButtonList nrbl = new RadioButtonList();
for (char ia = 'A'; ia <= 'D'; ia++)
{
ListItem li = new ListItem();
li.Text = ia.ToString() + "、" + mySet.Tables[0].Rows[int.Parse(lsts[i])]["q_key" + ia.ToString()].ToString();
li.Value = ia.ToString();
nrbl.Items.Add(li);
}
nrbl.ID = "q_" + mySet.Tables[0].Rows[int.Parse(lsts[i])]["q_id"].ToString();
ntc.Controls.Add(nrbl);
}
Button1.Visible = true;
}
private string roandow_data(int allcount, int thecount)
{
Random rnd = new Random();
List<int> lst = new List<int>();
int i = 0;
string str = "";
while (i < thecount)
{
int j = rnd.Next(allcount);
if (lst.IndexOf(j) == -1)
{
lst.Add(j);
i++;
}
}
foreach (int j in lst)
{
if (str.Length == 0)
{
str = j.ToString();
}
else
{
str = str + ";" + j.ToString();
}
}
return str;哪位能够解答下!!
解决方案 »
- .NET中,如何还原js escape过的编码?
- 学习中遇到了些问题,关于RadioButtonList的问题。
- asp:UpdatePanel 还是刷新……
- 后台数据显示到前台,最快的方法是什么
- 如何用VS2003打包后安装时在用户的桌面上建立一个快捷方式?
- 授予 ASP.Net 对于某个目录有写入权限,请问这个该怎么设置呢
- 凭账号密码从数据库中筛选出相应的信息显示在网页上
- 请教:Asp.net在本机上用vs.net开发时是不是一定要在本机上装IIS呢?
- 增加xml节点时为什么自动给节点增加了一个命名空间呢?
- treeview的缩进问题?我怎么样作才能把treeview中的节点之间的距离,显示的时候能够紧凑一些呢?默认的间距太大了!!!
- 请各位高手帮我看看这段C#代码实现的什么功能
- lucene.net 搜索中如何按时间排序标题 最匹配的几个结果的顺序
{
Random rnd = new Random();
List<int> lst = new List<int>();
int i = allcount;
string str = ""; while (i < thecount)
{ /*int j = rnd.Next(allcount);*/ if (lst.IndexOf(i) == -1)
{
lst.Add(i);
i++;
}
}
foreach (int j in lst)
{
if (str.Length == 0)
{
str = j.ToString();
}
else
{
str = str + ";" + j.ToString();
}
}
return str;}