我的问题是这样的,我要把试卷表内容显示出来,Questions(Questionid,title,picture,...), 
Answers(id,title,answer, Questionid ..)
        1   a     aaa      1
        2   b     bbb      1
       ...
            a     ccc      5
是选择题,我设想用datalist中潜入一两行的表格,先随机抽取试题,再在下面行嵌入rudiobuttonlist控件,逐个绑定各个选项。整个实现过程应该怎么样呢?在html中绑定的代码应该怎么写呢?

解决方案 »

  1.   

    你在此DATALIST绑定数据之后,马上循环进行绑定单选框
    //定义一个键值
    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();
    }如下做法,即可实现你的要求
      

  2.   

    上面漏写了一段,你的单选框应先求取
    RadioButtonList myradio = (RadioButtonList)this.datalist.Items[i].FindControl然后下面的this.RadioButtonList全部改为myradio
      

  3.   

    Text='<%# GetName(DataBinder.Eval(Container, "DataItem.PT_STATUS").ToString()%>'