我的问题是这样的,我要把试卷表内容显示出来,Questions(Questionid,title,picture,...),
Answers(id,title,answer, Questionid ..)
1 a aaa 1
2 b bbb 1
...
a ccc 5
是选择题,我设想用datalist中潜入一两行的表格,先随机抽取试题,再在下面行嵌入rudiobuttonlist控件,逐个绑定各个选项。整个实现过程应该怎么样呢?在html中绑定的代码应该怎么写呢?
Answers(id,title,answer, Questionid ..)
1 a aaa 1
2 b bbb 1
...
a ccc 5
是选择题,我设想用datalist中潜入一两行的表格,先随机抽取试题,再在下面行嵌入rudiobuttonlist控件,逐个绑定各个选项。整个实现过程应该怎么样呢?在html中绑定的代码应该怎么写呢?
//定义一个键值
stirng myKeyid = "";
for(int i=0;i<this.DataList1.Items.Count;i++)
{
myKeyid = this.DataList1.DataKeys[i].ToString();
//根据此ID求取此题目的几个选项(从数据库中)
sql = "select id,name from table where parentid = '" + myKeyid + "' ";
this.RadioButtonList.DataSource = 根据上述SQL求取到的数据源
this.RadioButtonList.DataValueField = "id";
this.RadioButtonList.DataTextField = "name";
this.RadioButtonList.DataBind();
}如下做法,即可实现你的要求
RadioButtonList myradio = (RadioButtonList)this.datalist.Items[i].FindControl然后下面的this.RadioButtonList全部改为myradio