下面是明日科技在线考试自动生成试题代码
问题1:怎样用session保存从数据库tb_Questions表中检索出的id和que_answer两个字段的数据?
问题2: 怎样用label或类似的控件保存从数据库tb_Questions表中检索出的id和que_answer两个字段的数据?//从数据库中选择单选题
case 1:
SqlDataAdapter myadapter1 = new SqlDataAdapter("select * "
+ "from tb_Questions where que_type='语文题'and que_lessonid='"
+ dd1 + "'and que_taotiid='" + dd2 + "'order by newid()", con);
DataSet myds1 = new DataSet();
myadapter1.Fill(myds1);
DataList1.DataSource = myds1;
DataList1.DataBind();
//生成单选题题号
for (int tID1 = 1; tID1 <= DataList1.Items.Count; tID1++)
{
Label lblSelect = (Label)DataList1.Items[tID1 - 1].FindControl("Label2");
lblSelect.Text = tID1.ToString() + "、";
}
break;
问题1:怎样用session保存从数据库tb_Questions表中检索出的id和que_answer两个字段的数据?
问题2: 怎样用label或类似的控件保存从数据库tb_Questions表中检索出的id和que_answer两个字段的数据?//从数据库中选择单选题
case 1:
SqlDataAdapter myadapter1 = new SqlDataAdapter("select * "
+ "from tb_Questions where que_type='语文题'and que_lessonid='"
+ dd1 + "'and que_taotiid='" + dd2 + "'order by newid()", con);
DataSet myds1 = new DataSet();
myadapter1.Fill(myds1);
DataList1.DataSource = myds1;
DataList1.DataBind();
//生成单选题题号
for (int tID1 = 1; tID1 <= DataList1.Items.Count; tID1++)
{
Label lblSelect = (Label)DataList1.Items[tID1 - 1].FindControl("Label2");
lblSelect.Text = tID1.ToString() + "、";
}
break;
你是要把这些东西展示在页面,就用repeater或者 GridView绑定展示 动态生成label也行 ,但麻烦些!