473,769 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Urgent - How to access all radiobuttonlist s in a loop (c# asp.net)

C# asp.net 2.0.

I'm creating an online survey. I'm making a string array that's holding the
variables of the answers made in the radiobuttonlist s that i create manually.
I need to make a method that loops through all the radiobuttonlist s and puts
the selected answers in the string array that i've created. I guess this is
relatively easy, but I haven't figured it out..here's the code that I have
for now:

protected void cmdSave_Click(o bject sender, EventArgs e)
{
string date = MakeMySqlDateTi me();

int numberOfAnswers = 24; //Also the number of radiobuttonlist s
string[] a = new string[numberOfAnswers]; //Variables to hold the
values until the insertion

//ALL THE RADIOBUTTONLIST S GOES HERE:
for (int i = 0; i <= numberOfAnswers ; i++)
{
a[i] = HERE I NEED TO ACCESS ALL THE RADIOBUTTONLIST S
}
a1 = rbl1.SelectedVa lue.ToString();

//-----END OF RADIOBUTTONLIST S----

Can someone please give me some hints and code to help me?

Thanks!
Aug 18 '06 #1
6 7268
Try this (assuming the form is named as form1):

foreach (Control c in this.form1.Cont rols)
{
if (c is RadioButtonList )
{
Response.Write( ((RadioButtonLi st)c).SelectedV alue + "<br/>");
}
}

If you have nested RadioButtonList in any container controls then you will
have to run this loop recursively for each of those containers...

"Svein Erik" <Sv*******@disc ussions.microso ft.comwrote in message
news:BD******** *************** ***********@mic rosoft.com...
C# asp.net 2.0.

I'm creating an online survey. I'm making a string array that's holding the
variables of the answers made in the radiobuttonlist s that i create
manually.
I need to make a method that loops through all the radiobuttonlist s and puts
the selected answers in the string array that i've created. I guess this is
relatively easy, but I haven't figured it out..here's the code that I have
for now:

protected void cmdSave_Click(o bject sender, EventArgs e)
{
string date = MakeMySqlDateTi me();

int numberOfAnswers = 24; //Also the number of radiobuttonlist s
string[] a = new string[numberOfAnswers]; //Variables to hold the
values until the insertion

//ALL THE RADIOBUTTONLIST S GOES HERE:
for (int i = 0; i <= numberOfAnswers ; i++)
{
a[i] = HERE I NEED TO ACCESS ALL THE RADIOBUTTONLIST S
}
a1 = rbl1.SelectedVa lue.ToString();

//-----END OF RADIOBUTTONLIST S----

Can someone please give me some hints and code to help me?

Thanks!

Aug 18 '06 #2
Ok, that worked, thanks, but now I have another small issue...If the user
selected the "Other" option, he's supposed to write text into a textbox
beside the radiobuttonlist . How can I identify whict textbox to retrieve
from, from within the loop?
Here is the code:

int controlCounter = 0;

foreach (Control c in this.survey.Con trols)
{
if (c is RadioButtonList )
{
a[controlCounter] = ((RadioButtonLi st)c).SelectedV alue;
if (a[controlCounter].ToString() == "Other:")
{
//How can i determine which textbox to grab the text
from, I have several radiobuttonlist s that contains the "Other:" option..
}
controlCounter+ +;
}
}

"Siva M" wrote:
Try this (assuming the form is named as form1):

foreach (Control c in this.form1.Cont rols)
{
if (c is RadioButtonList )
{
Response.Write( ((RadioButtonLi st)c).SelectedV alue + "<br/>");
}
}

If you have nested RadioButtonList in any container controls then you will
have to run this loop recursively for each of those containers...

"Svein Erik" <Sv*******@disc ussions.microso ft.comwrote in message
news:BD******** *************** ***********@mic rosoft.com...
C# asp.net 2.0.

I'm creating an online survey. I'm making a string array that's holding the
variables of the answers made in the radiobuttonlist s that i create
manually.
I need to make a method that loops through all the radiobuttonlist s and puts
the selected answers in the string array that i've created. I guess this is
relatively easy, but I haven't figured it out..here's the code that I have
for now:

protected void cmdSave_Click(o bject sender, EventArgs e)
{
string date = MakeMySqlDateTi me();

int numberOfAnswers = 24; //Also the number of radiobuttonlist s
string[] a = new string[numberOfAnswers]; //Variables to hold the
values until the insertion

//ALL THE RADIOBUTTONLIST S GOES HERE:
for (int i = 0; i <= numberOfAnswers ; i++)
{
a[i] = HERE I NEED TO ACCESS ALL THE RADIOBUTTONLIST S
}
a1 = rbl1.SelectedVa lue.ToString();

//-----END OF RADIOBUTTONLIST S----

Can someone please give me some hints and code to help me?

Thanks!

Aug 18 '06 #3
Well, the simple way is to check the ID radio button list (in case of
"Other") and get the associated text box value by hardcoding the textbox ID.

"Svein Erik" <Sv*******@disc ussions.microso ft.comwrote in message
news:91******** *************** ***********@mic rosoft.com...
Ok, that worked, thanks, but now I have another small issue...If the user
selected the "Other" option, he's supposed to write text into a textbox
beside the radiobuttonlist . How can I identify whict textbox to retrieve
from, from within the loop?
Here is the code:

int controlCounter = 0;

foreach (Control c in this.survey.Con trols)
{
if (c is RadioButtonList )
{
a[controlCounter] = ((RadioButtonLi st)c).SelectedV alue;
if (a[controlCounter].ToString() == "Other:")
{
//How can i determine which textbox to grab the text
from, I have several radiobuttonlist s that contains the "Other:" option..
}
controlCounter+ +;
}
}

"Siva M" wrote:
Try this (assuming the form is named as form1):

foreach (Control c in this.form1.Cont rols)
{
if (c is RadioButtonList )
{
Response.Write( ((RadioButtonLi st)c).SelectedV alue + "<br/>");
}
}

If you have nested RadioButtonList in any container controls then you will
have to run this loop recursively for each of those containers...

"Svein Erik" <Sv*******@disc ussions.microso ft.comwrote in message
news:BD******** *************** ***********@mic rosoft.com...
C# asp.net 2.0.

I'm creating an online survey. I'm making a string array that's holding
the
variables of the answers made in the radiobuttonlist s that i create
manually.
I need to make a method that loops through all the radiobuttonlist s and
puts
the selected answers in the string array that i've created. I guess this
is
relatively easy, but I haven't figured it out..here's the code that I have
for now:

protected void cmdSave_Click(o bject sender, EventArgs e)
{
string date = MakeMySqlDateTi me();

int numberOfAnswers = 24; //Also the number of radiobuttonlist s
string[] a = new string[numberOfAnswers]; //Variables to hold the
values until the insertion

//ALL THE RADIOBUTTONLIST S GOES HERE:
for (int i = 0; i <= numberOfAnswers ; i++)
{
a[i] = HERE I NEED TO ACCESS ALL THE RADIOBUTTONLIST S
}
a1 = rbl1.SelectedVa lue.ToString();

//-----END OF RADIOBUTTONLIST S----

Can someone please give me some hints and code to help me?

Thanks!

Aug 18 '06 #4
But this is inside a loop, how can i hardcode the ID when I don't know whicth
radiobuttonlist the loop is at?

Is there another way of doing this?

"Siva M" wrote:
Well, the simple way is to check the ID radio button list (in case of
"Other") and get the associated text box value by hardcoding the textbox ID.

"Svein Erik" <Sv*******@disc ussions.microso ft.comwrote in message
news:91******** *************** ***********@mic rosoft.com...
Ok, that worked, thanks, but now I have another small issue...If the user
selected the "Other" option, he's supposed to write text into a textbox
beside the radiobuttonlist . How can I identify whict textbox to retrieve
from, from within the loop?
Here is the code:

int controlCounter = 0;

foreach (Control c in this.survey.Con trols)
{
if (c is RadioButtonList )
{
a[controlCounter] = ((RadioButtonLi st)c).SelectedV alue;
if (a[controlCounter].ToString() == "Other:")
{
//How can i determine which textbox to grab the text
from, I have several radiobuttonlist s that contains the "Other:" option..
}
controlCounter+ +;
}
}

"Siva M" wrote:
Try this (assuming the form is named as form1):

foreach (Control c in this.form1.Cont rols)
{
if (c is RadioButtonList )
{
Response.Write( ((RadioButtonLi st)c).SelectedV alue + "<br/>");
}
}

If you have nested RadioButtonList in any container controls then you will
have to run this loop recursively for each of those containers...

"Svein Erik" <Sv*******@disc ussions.microso ft.comwrote in message
news:BD******** *************** ***********@mic rosoft.com...
C# asp.net 2.0.

I'm creating an online survey. I'm making a string array that's holding
the
variables of the answers made in the radiobuttonlist s that i create
manually.
I need to make a method that loops through all the radiobuttonlist s and
puts
the selected answers in the string array that i've created. I guess this
is
relatively easy, but I haven't figured it out..here's the code that I have
for now:

protected void cmdSave_Click(o bject sender, EventArgs e)
{
string date = MakeMySqlDateTi me();

int numberOfAnswers = 24; //Also the number of radiobuttonlist s
string[] a = new string[numberOfAnswers]; //Variables to hold the
values until the insertion

//ALL THE RADIOBUTTONLIST S GOES HERE:
for (int i = 0; i <= numberOfAnswers ; i++)
{
a[i] = HERE I NEED TO ACCESS ALL THE RADIOBUTTONLIST S
}
a1 = rbl1.SelectedVa lue.ToString();

//-----END OF RADIOBUTTONLIST S----

Can someone please give me some hints and code to help me?

Thanks!

Aug 18 '06 #5
foreach (Control c in this.form1.Cont rols)
{
if (c is RadioButtonList )
{

if ((RadioButtonLi st)c).SelectedV alue == "Other")
{
switch (c.ID)
{
case "CityList":
otherCity = txtCity.Text;
break;
case "FavoriteAuthor List":
otherFavAuthor = txtFavAuthor.Te xt;
break;
}
}
}
}
"Svein Erik" <Sv*******@disc ussions.microso ft.comwrote in message
news:D0******** *************** ***********@mic rosoft.com...
But this is inside a loop, how can i hardcode the ID when I don't know
whicth
radiobuttonlist the loop is at?

Is there another way of doing this?

"Siva M" wrote:
Well, the simple way is to check the ID radio button list (in case of
"Other") and get the associated text box value by hardcoding the textbox
ID.

"Svein Erik" <Sv*******@disc ussions.microso ft.comwrote in message
news:91******** *************** ***********@mic rosoft.com...
Ok, that worked, thanks, but now I have another small issue...If the user
selected the "Other" option, he's supposed to write text into a textbox
beside the radiobuttonlist . How can I identify whict textbox to retrieve
from, from within the loop?
Here is the code:

int controlCounter = 0;

foreach (Control c in this.survey.Con trols)
{
if (c is RadioButtonList )
{
a[controlCounter] = ((RadioButtonLi st)c).SelectedV alue;
if (a[controlCounter].ToString() == "Other:")
{
//How can i determine which textbox to grab the text
from, I have several radiobuttonlist s that contains the "Other:" option..
}
controlCounter+ +;
}
}

"Siva M" wrote:
Try this (assuming the form is named as form1):

foreach (Control c in this.form1.Cont rols)
{
if (c is RadioButtonList )
{
Response.Write( ((RadioButtonLi st)c).SelectedV alue + "<br/>");
}
}

If you have nested RadioButtonList in any container controls then you
will
have to run this loop recursively for each of those containers...

"Svein Erik" <Sv*******@disc ussions.microso ft.comwrote in message
news:BD******** *************** ***********@mic rosoft.com...
C# asp.net 2.0.

I'm creating an online survey. I'm making a string array that's holding
the
variables of the answers made in the radiobuttonlist s that i create
manually.
I need to make a method that loops through all the radiobuttonlist s and
puts
the selected answers in the string array that i've created. I guess this
is
relatively easy, but I haven't figured it out..here's the code that I
have
for now:

protected void cmdSave_Click(o bject sender, EventArgs e)
{
string date = MakeMySqlDateTi me();

int numberOfAnswers = 24; //Also the number of radiobuttonlist s
string[] a = new string[numberOfAnswers]; //Variables to hold
the
values until the insertion

//ALL THE RADIOBUTTONLIST S GOES HERE:
for (int i = 0; i <= numberOfAnswers ; i++)
{
a[i] = HERE I NEED TO ACCESS ALL THE RADIOBUTTONLIST S
}
a1 = rbl1.SelectedVa lue.ToString();

//-----END OF RADIOBUTTONLIST S----

Can someone please give me some hints and code to help me?

Thanks!

Aug 18 '06 #6
Thanks, that was excactly what i was started on :)

but damn...I thought that i could make this totally automatic with a few
loops..

"Siva M" wrote:
foreach (Control c in this.form1.Cont rols)
{
if (c is RadioButtonList )
{

if ((RadioButtonLi st)c).SelectedV alue == "Other")
{
switch (c.ID)
{
case "CityList":
otherCity = txtCity.Text;
break;
case "FavoriteAuthor List":
otherFavAuthor = txtFavAuthor.Te xt;
break;
}
}
}
}
"Svein Erik" <Sv*******@disc ussions.microso ft.comwrote in message
news:D0******** *************** ***********@mic rosoft.com...
But this is inside a loop, how can i hardcode the ID when I don't know
whicth
radiobuttonlist the loop is at?

Is there another way of doing this?

"Siva M" wrote:
Well, the simple way is to check the ID radio button list (in case of
"Other") and get the associated text box value by hardcoding the textbox
ID.

"Svein Erik" <Sv*******@disc ussions.microso ft.comwrote in message
news:91******** *************** ***********@mic rosoft.com...
Ok, that worked, thanks, but now I have another small issue...If the user
selected the "Other" option, he's supposed to write text into a textbox
beside the radiobuttonlist . How can I identify whict textbox to retrieve
from, from within the loop?
Here is the code:

int controlCounter = 0;

foreach (Control c in this.survey.Con trols)
{
if (c is RadioButtonList )
{
a[controlCounter] = ((RadioButtonLi st)c).SelectedV alue;
if (a[controlCounter].ToString() == "Other:")
{
//How can i determine which textbox to grab the text
from, I have several radiobuttonlist s that contains the "Other:" option..
}
controlCounter+ +;
}
}

"Siva M" wrote:
Try this (assuming the form is named as form1):
>
foreach (Control c in this.form1.Cont rols)
{
if (c is RadioButtonList )
{
Response.Write( ((RadioButtonLi st)c).SelectedV alue + "<br/>");
}
}
>
If you have nested RadioButtonList in any container controls then you
will
have to run this loop recursively for each of those containers...
>
"Svein Erik" <Sv*******@disc ussions.microso ft.comwrote in message
news:BD******** *************** ***********@mic rosoft.com...
C# asp.net 2.0.
>
I'm creating an online survey. I'm making a string array that's holding
the
variables of the answers made in the radiobuttonlist s that i create
manually.
I need to make a method that loops through all the radiobuttonlist s and
puts
the selected answers in the string array that i've created. I guess this
is
relatively easy, but I haven't figured it out..here's the code that I
have
for now:
>
protected void cmdSave_Click(o bject sender, EventArgs e)
{
string date = MakeMySqlDateTi me();
>
int numberOfAnswers = 24; //Also the number of radiobuttonlist s
string[] a = new string[numberOfAnswers]; //Variables to hold
the
values until the insertion
>
//ALL THE RADIOBUTTONLIST S GOES HERE:
for (int i = 0; i <= numberOfAnswers ; i++)
{
a[i] = HERE I NEED TO ACCESS ALL THE RADIOBUTTONLIST S
}
a1 = rbl1.SelectedVa lue.ToString();
>
//-----END OF RADIOBUTTONLIST S----
>
Can someone please give me some hints and code to help me?
>
Thanks!
>
>

Aug 18 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
3347
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to speed. I like books with practical exercises, and also with test questions (like cert books) *2*
3
2587
by: Me | last post by:
Is it possible to use ASP.net with Microsoft Access. From what I can find ASP.net only works with SQL server. That's kind of step backward from being able to access any data source.
6
1359
by: Woody Splawn | last post by:
It is real important to choose the right tool for a given problem and it is not clear to me just what the advantage of VS.net is over Access, for example, when writing a non-web applicaiton. I see the strengths of VB.net when it comes to the web but what about non-web applications. VB.net is complicated, but that's ok and I feel that this is not a reason by itself to choose Access over VB.net. What other argurments in VB.net's favor are...
10
1770
by: Gerald Bader | last post by:
Hello! I've got an MS Access Application and a VB.NET Application. Now I want to to exchange information in real time between these two applications. For example the VB.NET application wants to know the name of the active Form within the Access application. Or the Access application wants to know the date within a textbox of the VB.NET application. And so on...
4
4286
by: Anns via SQLMonster.com | last post by:
My company currently has about 20-25 Ms Access Database that they want to replace the FE with .net and the BE on SQL. This will be done using Visual Studio 2005. Once the FE is converted to .net and the BE is SQL they all will be accessed through our intranet (sharepoint). I work in Ms Access and intermediate at VBA and just learing SQL through the ENTERPRISE MANAGER SCREEN.
7
7358
by: rguarnieri | last post by:
Hi! I'm trying to create a query with a boolean expression like this: select (4 and 1) as Value from Table1 this query return always -1, but when I make the same calculation in visual basic, the value returned is 0. Can anyone tell me why the expression (4 and 1) return different value
2
2102
by: rajesh.us.it.recruiter | last post by:
Dear Professionals We have urgent requirements for J2EE, .Net, Siebel-CRM, Oracle Apps, SAP ERP, Mainframe, C++, Unix Professional on H1 Transfer in Bay Area. If you are looking out for a project. Kindly forward your CV to rajesh.us.it.recruiter@gmail.com The Candidate should have a Valid H1 Visa and Should be ready to appear
2
1703
by: sbowman | last post by:
I've seen a lot of tools out there that automatically convert Access apps to .NET. If anyone has used one, I'd like to know which one and what you thought of it. Are they really worth the money? Thanks, Shelley
3
1641
by: =?Utf-8?B?bXNjZXJ0aWZpZWQ=?= | last post by:
Has anyone successfully used an Access query from .NET? I am trying to do this and am getting a weird error. .NET calls queries 'stored procedures'. The error I am getting says "Schema could not be retrieved for this stored procedure' ... "The underlying enumerator did not support enumerating objects of type 'ProcedureParamater'". .Net does recognize the stored procedure i.e. it does appear in the drop-sdown list.
0
1646
Kosal
by: Kosal | last post by:
Hi Please help me to create AdRotator using Database Access in ASP.NET if everyone can because I don't know how to create table AdList in access and how to contect to access and get data from Access to display. please help to create sample AdRotator.aspx and database complete all becuaes I don't know. I am looking from here as soon as posible. thanks
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.