从数据库提取题目
列如:
1. 你对该产品是否满意
满意  不满意  一般  很满意(是单选钮)
动态生成的题目,怎么动态生成radio,保存答案的时候还需要把题号保存到数据库中。

解决方案 »

  1.   

    这种情况很常见,调查问卷中经常有单选或者复选的情况。
    单选就输出:
    <input type="radion" name="*name1" checked="true">满意
    <input type="radion" name="*name2" checked="true">不满意
    <input type="radion" name="*name3" checked="true">一般
    <input type="radion" name="*name4" checked="true">很满意复选就是type="checkbox"了
      

  2.   

    做成用户控件..用户控件里 去例如
     for (int i = 0; i != 10; i++)
                {
                    RadioButton _Button = new RadioButton();
                    _Button.Text = i.ToString();
                    _Button.Dock = DockStyle.Left;
                    panel1.Controls.Add(_Button);
                }
      

  3.   

    Js下面利用document.createElement("input")来创建就行了。最后AppendChild到指定的位置就可以了。
      

  4.   


    int i=1;
    foreach(DataRow dr in dt.Rows)
    {
    tbRow=new HtmlTableRow();
    tbCell=new HtmlTableCell();
    string subject=i+". "+dr["F_Subject"].ToString();
    string id=dr["F_SEQ"].ToString()+"_"+"RdoBtnList"; string cellContent=string.Empty;
    cellContent="<table cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">";
    cellContent +="<tr><td>"+subject+"</td></tr>";
    cellContent +="<tr><td><asp:RadioButtonList id=\""+id+"\" runat=\"server\" RepeatDirection=\"Horizontal\">";
    cellContent +="<asp:ListItem Value=\"1\">非常不同意</asp:ListItem>";
    cellContent +="<asp:ListItem Value=\"2\">不同意</asp:ListItem>";
    cellContent +="<asp:ListItem Value=\"3\">一般</asp:ListItem>";
    cellContent +="<asp:ListItem Value=\"4\">同意</asp:ListItem>";
    cellContent +="<asp:ListItem Value=\"5\">非常同意</asp:ListItem>";
    cellContent +="</td></tr></table>"; tbCell.InnerHtml=cellContent;
    tbRow.Cells.Add(tbCell);
    this.tbList.Rows.Add(tbRow);
    i=i+1;
    }
    这样是不对的  
      

  5.   

    并且不好提取  所选择的radio的值
      

  6.   

    保存答案的时候还需要把题号保存到数据库中。1. 你对该产品是否满意 
    <input type="hidden" name="subject1" value="1">
    用隐藏域来保存题号还可以用以个递增的变量来保存。。看你的需求。。
      

  7.   

    本帖最后由 ojlovecd 于 2009-07-23 14:35:26 编辑
      

  8.   

    在cs文件中可以直接用Request.Form[]获取???
      

  9.   


    <asp:Repeater ID="RepeaterTry" runat="server">
                            <ItemTemplate>   
                                  <li>            
                                    <label><input type= "radio" id="aaaa<%#Container.ItemIndex+1%>" name="aaaa" /><%#DataBinder.Eval(Container.DataItem, "aaaa")%>  </label>                  
                                   
                                </li>    
                            </ItemTemplate>                    
                        </asp:Repeater>  后台给一个list数据源