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();
为什么我点击一次的时候就可以读下道题,,当我点击第二次的时候 页面没有变化,无法读出下道题。。,,是怎么回事 请高手帮忙看看
另外这种思路不知道是否合理,,是不是有更好的方法。请高手指点,,在线等。
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();
为什么我点击一次的时候就可以读下道题,,当我点击第二次的时候 页面没有变化,无法读出下道题。。,,是怎么回事 请高手帮忙看看
另外这种思路不知道是否合理,,是不是有更好的方法。请高手指点,,在线等。
解决方案 »
- asp.net MVC 全民大调查
- datagrid显示对话框
- 关闭浏览器事件,怎么弄啊
- 请问要画出像这种图。要使用什么软件?
- 初学者急!!调用WEB Service总是说:找不到文件或程序集名称“p-lcwdin.dll”,或找不到它的一个依赖项。
- propertyGrid控件问题
- 在图片上传前判断图片宽度 ,我都快被搞疯掉了
- asp.net中关于Application[Session["style"].ToString()+"xtable_bgcolor"]
- 请问我想把一个DataSet导出成Excel文件提供下载,我该如何做?
- 如何做到上传图片然后把图片resize成统一的尺寸,然后加上边框?
- 让各位长长见识,如何在平面上画3D图
- 这样的登陆问题如何解决呢?
因为 基本是 从头开始做, 有很多人用同一个试题!