Re: Using a String value as a RadioButton object reference
From: Bill McCarthy
Date: 03/30/04
- Next message: Ayaz Ahmed: "Re: PrintPreviewDialog printing bug"
- Previous message: Cor: "Re: drop down list in datagrid"
- In reply to: Cor: "Re: Using a String value as a RadioButton object reference"
- Next in thread: Cor: "Re: Using a String value as a RadioButton object reference"
- Reply: Cor: "Re: Using a String value as a RadioButton object reference"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 30 Mar 2004 17:06:11 +1000
Alternatively, if it is a ASP.ENT application, then he can use the Page's
FindControl method to return the actual radiobutton given it's name.
The efficiency of which method to use would depend on the number of other
controls on the page. If there are many non radio buttons, or that only some of
the radio buttons information is required in the given code block, or they need
to be retrieved in a given order, then using FindControl would be preferable. If
there are mainly only radiobuttons and all of them need to be enumerate through
in no given order, then using the control's collection would be preferable.
Bill.
"Cor" <non@non.com> wrote in message
news:ONLpoNiFEHA.1600@tk2msftngp13.phx.gbl...
> Hi Mike,
>
> We did seen this question not for a long while, it was often in this
> newsgroup
>
> I type it here new watch typos.
>
> I take the most simple one which asumes that the buttons are all direct on
> the form, just to show you how.
>
> When the buttons are on a panel or whatever, there are a lot alternatives
> (recursion or whatever).
>
> This is a winform sample in a webform it needs a little bit in an other way.
> I did not write it direct in your sample, because I asume that will become
> very long.
>
> \\\
> dim ctr as control
> for each ctr in me.controls
> if typeof ctr is radiobutton then
> if directcast(ctr,radiobutton).name.substring(0) = "Mybuttonname"
> 'do what you want to do with ctr.xxxx
> end if
> end if
> next
> ///
> I hope this helps?
>
> Cor
>
>
> "Mike Bazoo" <mike_bazoo@hotmail.com> schreef in bericht
> news:62023689.0403292020.7ec480d0@posting.google.com...
> > I am a novice vb.net programmer and hope someone can help me.
> >
> > For a questionnaire, I have several (100+) radio buttons whose names
> > follow this standard:
> > radAlways1, radAlways2, 3.. 10
> > radUsually1, radUsually2, 3...10
> > radSometimes1, radSometimes2, 3...10
> > etc
> >
> > My ultimate goal is to loop through each one and do an action on the
> > ones that are 'Checked'.
> >
> > In order to try to reduce the amount of code, I created Strings inside
> > each loop which generate radio buttons names. Something like this:
> >
> > For intCount = 0 To 10
> > strAlways = "radAlways" & intCount + 1
> > strUsually = "radUsually" & intCount + 1
> > strSometimes = "radSometimes" & intCount + 1
> > strSeldom = "radSeldom" & intCount + 1
> > strNever = "radNever" & intCount + 1
> >
> > ...'Rest of code here
> > Next intCount
> >
> > This part actually works fine which the strings having the right radio
> > buttons names in each loop iteration.
> >
> > Now, my question is: how can I use this correctly generated string as
> > the RadioButton object in order to be able to call RadioButton's
> > methods ('Checked' in particular)?
> >
> > For intCount = 0 To 2
> > strAlways = "radAlways" & intCount + 1
> > strUsually = "radUsually" & intCount + 1
> > strSometimes = "radSometimes" & intCount + 1
> >
> > 'HERE IS WHERE I WANT TO USE THE STRING VALUE
> > 'AS THE RADIOBUTTON IN ORDER TO CALL THE 'CHECKED' METHOD.
> > 'I DO NOT WANT TO HARDCODE THE ACTUAL RADIOBUTTON OBJECT
> > NAME.
> > If radAlways1.Checked = True Then
> > 'do something
> > ElseIf radUsually1.Checked = True Then
> > 'do something
> > ElseIf radSometimes1.Checked = True Then
> > 'do something
> > End If
> > Next intCount
> >
> > I am also open for other ideas on how to accomplish this.
> > Thanks.
>
>
- Next message: Ayaz Ahmed: "Re: PrintPreviewDialog printing bug"
- Previous message: Cor: "Re: drop down list in datagrid"
- In reply to: Cor: "Re: Using a String value as a RadioButton object reference"
- Next in thread: Cor: "Re: Using a String value as a RadioButton object reference"
- Reply: Cor: "Re: Using a String value as a RadioButton object reference"
- Messages sorted by: [ date ] [ thread ]