|
-
Jun 7th, 2006, 04:24 AM
#1
Thread Starter
Hyperactive Member
Radiobutton loop
Hi
I was just wondering if any of you guys know how to do this in c#
Code:
for (int cntr = 0; cntr < 2; cntr++)
{
rbtnAns[cntr].text = arrChoice[cntr];
}
Basically, i've got three radiobuttons (rbtnAns1, rbtnAns2 & rbtnAns3) which should display arrChoice that I've declared and created earlier as arrays.
I've tried using this code in c#
Code:
for (int cntr = 0; cntr < 2; cntr++)
{
((RadioButton)this.FindControl("rbtnAns" + (cntr+1))).Text = (arrChoice[cntr]).Tostring();
}
and include these header files:
using System.Web;
I was going to add using System.Web.UI----- but this option was not available
this means i cant get the FindControl() thing to work
Any help will be appreciated
-
Jun 7th, 2006, 04:37 AM
#2
Re: Radiobutton loop
Is this a WinForms app or an ASP.NET app? If it's WinForms then of course not, because Web.UI is for Web applications. You've got three RadioButtons so why do you even need a loop? Also, are you sure that RadioButtons are what you want? Only one of them can be checked at a time. If that's what you want then cool but if not then you should use CheckBoxes.
-
Jun 7th, 2006, 04:51 AM
#3
Thread Starter
Hyperactive Member
Re: Radiobutton loop
I'm using WinForms app...
I chose to use the radiobuttons because i'm creating a multiple choice test program for Year 7 pipol....
All the preset questions and answers are declared and saved as an array...
i know it is possible to do using something like this:
Code:
public virtual Control FindControl (string id)
{
//not sure though what to write here!
}
but without using needing to use the header file (using system.Web) at all:
-
Jun 7th, 2006, 04:53 AM
#4
Thread Starter
Hyperactive Member
Re: Radiobutton loop
referring to the one above:
where id is the identifier for the control to be found
-
Jun 7th, 2006, 05:22 AM
#5
Re: Radiobutton loop
I've posted code in then Codebank to visit every control on a form. You could use that and test the Name property until you find a match.
-
Jun 8th, 2006, 02:59 AM
#6
Thread Starter
Hyperactive Member
Re: Radiobutton loop
Can u pls explain on how im going to do that....
Code:
Control ctl = this.GetNextControl(this, true); // Get the first control in the tab order.
while (ctl != null)
{
// Use ctl here. --> what to put in here in this case
ctl = this.GetNextControl(ctl, true); // Get the next control in the tab order.
}
I'm still kinda new to this type of lang..
sorz for the trouble
-
Jun 8th, 2006, 03:04 AM
#7
Re: Radiobutton loop
You want to find a control that has a particular name, so compare the Name of the control to the name you're looking for. If they are the same then retrun that control. If you get to the end of the loop without finding a match return null.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|