- 爱易网页
-
C#教程
- [请问]RadioButton怎么取值并插入数据库
日期:2014-05-19 浏览次数:20757 次
[请教]RadioButton如何取值并插入数据库
c#代码(用于Repeater1显示题目和选项):
protected void Page_Load(object sender, EventArgs e)
{
string connstring = ConfigurationManager.ConnectionStrings[ "Conn "].ConnectionString;
SqlConnection wtConn = new SqlConnection(connstring);
wtConn.Open();
SqlCommand Command = new SqlCommand( "select qus,auc01,auc02,auc03,auc04 from wenti ", wtConn);
SqlDataReader reader = Command.ExecuteReader();
Repeater1.DataSource = reader;
Repeater1.DataBind();
reader.Close();
wtConn.Close();
}
---------------------------------------
asp.net页面代码:
<asp:Repeater ID= "Repeater1 " runat= "server ">
<ItemTemplate>
<!--问题-->
<%# Eval( "qus ") %>
<!--选项-->
<asp:RadioButton ID= "RadioButton1 " GroupName= "rb " runat= "server " Text= "A " value= ' <%# Eval( "aus01 ") %> ' />
<asp:RadioButton ID= "RadioButton2 " GroupName= "rb " runat= "server " Text= "B " value= ' <%# Eval( "aus02 ") %> ' />
<asp:RadioButton ID= "RadioButton3 " GroupName= "rb " runat= "server " Text= "C " value= ' <%# Eval( "aus03 ") %> ' />
<asp:RadioButton ID= "RadioButton4 " GroupName= "rb " runat= "server " Text= "D " value= ' <%# Eval( "aus04 ") %> ' />
</ItemTemplate>
</asp:Repeater>
---------------------------------------
IE里显示出的效果(问题和选项都是从数据表中读出的,选项的value根据问题的不同有所差异):
问题1 ○A ○B ○C ○D
问题2 ○A ○B ○C ○D
问题3 ○A ○B ○C ○D
问题4 ○A ○B ○C ○D