| | |
How to retrieve data from a dynamically generated radio button
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2007
Posts: 13
Reputation:
Solved Threads: 0
Hi ,
I have been trying to create an online exam application and is facing some issue with dynamically generated radio buttons.
My problem is discussed below:
I have a table with a set of questions.I dispaly the questions on the screen with a set of dynamically generated radio buttons with the answer options . I also have a submit button.
On the click of the submit button i need all the selected answers to be stored in a table in db.
I am not able to retrieve the data from the selected radio button.
I have been trying out this since y'day and unfortunately couldn't solve this issue.
Could somebody help me out in solving this problem of mine.
Regards,
Aswathy
I have been trying to create an online exam application and is facing some issue with dynamically generated radio buttons.
My problem is discussed below:
I have a table with a set of questions.I dispaly the questions on the screen with a set of dynamically generated radio buttons with the answer options . I also have a submit button.
On the click of the submit button i need all the selected answers to be stored in a table in db.
I am not able to retrieve the data from the selected radio button.
I have been trying out this since y'day and unfortunately couldn't solve this issue.
Could somebody help me out in solving this problem of mine.
Regards,
Aswathy
I'd load the radio buttons into a panel or place holder, then in the code for the submit button I'd do something like
if(phRadioButtons.HasControls())
{
foreach(Control c in control.Controls)
{
Type type = c.GetType();
if(type.FullName == "System.Web.UI.WebControls.RadioButton")
then you can add code to read the value and add to the db
if(phRadioButtons.HasControls())
{
foreach(Control c in control.Controls)
{
Type type = c.GetType();
if(type.FullName == "System.Web.UI.WebControls.RadioButton")
then you can add code to read the value and add to the db
If you post some code we can help, hard to know what your issue is. Typically most people get stuck with dynamically created controls because they don't understand the page life cycle in ASP.NET. Are you using individual RadiButtons or a RadioButtonList server control or HTML input radio buttons? are they created in a datagrid template column or what? the best way to store/get the values differs depending on your implementation.
heres an example I've posted before in these forums. Its developed against the .NET 2.0 framework, you don't say which you are developing for:
ASPX
ASPX.CS
heres an example I've posted before in these forums. Its developed against the .NET 2.0 framework, you don't say which you are developing for:
ASPX
ASP.NET Syntax (Toggle Plain Text)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Radiolist.aspx.cs" Inherits="Radiolist" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server"> <Columns> <asp:TemplateField HeaderText="Select"> <ItemTemplate> <input type="radio" name="radiolist" value="<%# Container.DataItem%>" /> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Data"> <ItemTemplate> <%# Container.DataItem %> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> <asp:Label ID="lblSelected" runat="server"></asp:Label></div> </form> </body> </html>
ASPX.CS
ASP.NET Syntax (Toggle Plain Text)
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Radiolist : System.Web.UI.Page { String[] data = new String[5]; protected void Page_Load(object sender, EventArgs e) { for (int i = 0; i < 5; i++) { data[i] = i.ToString(); } GridView1.DataSource = data; GridView1.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { if (Request.Form["radiolist"] == null) lblSelected.Text = "You didn't choose anything"; else lblSelected.Text = "You choose " + Request.Form["radiolist"]; } }
•
•
Join Date: Feb 2007
Posts: 13
Reputation:
Solved Threads: 0
•
•
•
•
I'd load the radio buttons into a panel or place holder, then in the code for the submit button I'd do something like
if(phRadioButtons.HasControls())
{
foreach(Control c in control.Controls)
{
Type type = c.GetType();
if(type.FullName == "System.Web.UI.WebControls.RadioButton")
then you can add code to read the value and add to the db
That's working ....
![]() |
Similar Threads
- Radio button value in asp (ASP)
- Radio button help!! (ASP)
- dynamically generated textboxes & radio buttons php, insert into db (PHP)
- please help! this is urgent> how to retrieve data to my tabpage without using data fo (C#)
Other Threads in the ASP.NET Forum
- Previous Thread: Need suggestions for a video recorder/player for ASP.NET site
- Next Thread: Getting first day of the month
| Thread Tools | Search this Thread |
.net 3.5 ajax alltypeofvideos appliances asp asp.net bc30451 beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions control countryselector dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iis javascript list listbox login microsoft mouse mssql nameisnotdeclared news novell numerical opera panelmasterpagebuttoncontrols problem radio redirect registration relationaldatabases reportemail save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos vista visualstudio vs2008 web webapplications webdevelopemnt webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers






