动态生成radio 从数据库提取题目列如:1. 你对该产品是否满意满意 不满意 一般 很满意(是单选钮)动态生成的题目,怎么动态生成radio,保存答案的时候还需要把题号保存到数据库中。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这种情况很常见,调查问卷中经常有单选或者复选的情况。单选就输出:<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"了 做成用户控件..用户控件里 去例如 for (int i = 0; i != 10; i++) { RadioButton _Button = new RadioButton(); _Button.Text = i.ToString(); _Button.Dock = DockStyle.Left; panel1.Controls.Add(_Button); } Js下面利用document.createElement("input")来创建就行了。最后AppendChild到指定的位置就可以了。 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; }这样是不对的 并且不好提取 所选择的radio的值 保存答案的时候还需要把题号保存到数据库中。1. 你对该产品是否满意 <input type="hidden" name="subject1" value="1">用隐藏域来保存题号还可以用以个递增的变量来保存。。看你的需求。。 本帖最后由 ojlovecd 于 2009-07-23 14:35:26 编辑 在cs文件中可以直接用Request.Form[]获取??? <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数据源 请教一个蹩脚的问题 c#中,动态链接库的问题 水晶报表重复数据问题 a.aspx的textbox 传到ifram(b.aspx)的textbox 关于C#中的作图问题 怎样控制按钮上字的颜色 如何在C#中将EXCELL文件导入SQL server 2000中? 求定期删除目录和文件的代码 安装html help workshop出现“inf安装失败,原因拒绝访问” net_lover(孟子E章) : 继续 一个简单的问题 关于vs2005菜单问题(哪位高人给解决一下)
单选就输出:
<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"了
for (int i = 0; i != 10; i++)
{
RadioButton _Button = new RadioButton();
_Button.Text = i.ToString();
_Button.Dock = DockStyle.Left;
panel1.Controls.Add(_Button);
}
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;
}
这样是不对的
<input type="hidden" name="subject1" value="1">
用隐藏域来保存题号还可以用以个递增的变量来保存。。看你的需求。。
<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数据源