int id=System.Convert.ToInt16(reader["id"].ToString());
reader.Close();
this.myconn.sqlDA_subject.SelectCommand.CommandText="select * from english_subject where title_id="+id;
SqlDataReader reader_subject=this.myconn.sqlDA_subject.SelectCommand.ExecuteReader();
bool flag=true;
ArrayList idarray = new ArrayList();
while(reader_subject.Read())
{
if(flag==true)
{
lb_subject.Text=reader_subject["question"].ToString();
RadioButtonList1.Items[0].Text=" "+reader_subject["answer_1"].ToString();
RadioButtonList1.Items[0].Value="A";
RadioButtonList1.Items[1].Text=" "+reader_subject["answer_2"].ToString();
RadioButtonList1.Items[1].Value="B";
RadioButtonList1.Items[2].Text=" "+reader_subject["answer_3"].ToString();
RadioButtonList1.Items[2].Value="C";
RadioButtonList1.Items[3].Text=" "+reader_subject["answer_4"].ToString();
RadioButtonList1.Items[3].Value="D";
flag=false;
}
else
{
idarray.Add(reader_subject["id"].ToString());
}
ViewState["readid"]=idarray;
}
reader_subject.Close();
我将要出的题id(除了第一题)以数组的形式存在一个ViewState["readid"]里面,另外我在Button1_Click写以下代码,想要实现每当点击一下button的时候,就换另一道题
private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
ArrayList nextarray=(ArrayList)ViewState["readid"];
int nextid=System.Convert.ToInt16(nextarray[0].ToString());
this.myconn.sqlDA_subject.SelectCommand.CommandText="select * from english_subject where id="+nextid;
SqlDataReader nextreader=this.myconn.sqlDA_subject.SelectCommand.ExecuteReader();
if(nextreader.Read())
{
lb_subject.Text=nextreader["question"].ToString();
RadioButtonList1.Items[0].Text=" "+nextreader["answer_1"].ToString();
RadioButtonList1.Items[0].Value="A";
RadioButtonList1.Items[1].Text=" "+nextreader["answer_2"].ToString();
RadioButtonList1.Items[1].Value="B";
RadioButtonList1.Items[2].Text=" "+nextreader["answer_3"].ToString();
RadioButtonList1.Items[2].Value="C";
RadioButtonList1.Items[3].Text=" "+nextreader["answer_4"].ToString();
RadioButtonList1.Items[3].Value="D";
nextarray.RemoveAt(0);
ViewState["readid"]=nextarray;
}
else
{
lb_subject.Text="Database Error!";
}
nextreader.Close();
为什么我点击一次的时候就可以读下道题,,当我点击第二次的时候 页面没有变化,无法读出下道题。。,,是怎么回事 请高手帮忙看看
另外这种思路不知道是否合理,,是不是有更好的方法。请高手指点,,在线等。