Cerebrus
unread,Jun 25, 2008, 2:25:03 PM6/25/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Glenn is quite right. You need to add another If condition around your
If. One that checks if the type of control is in fact a RadioButton,
because only they will have the Checked property.
foreach (Control c in pnlRadio.Controls)
{
if (typeof(c) is RadioButton)
{
if (c.Checked == true)
{
// OMG, they *checked* the radiobutton !!!
}
}
}
On Jun 25, 11:11 pm, Glenn <
ke4ktza...@gmail.com> wrote:
> Your foreach loop is incorrect. Doing it the way you specified is not going
> to get just the RadioButton controls from your container. It is going to
> get EVERY control from your container. In your case, it is getting another
> type of control and trying to typecast it to a RadioButton. Hense the error
> you are getting.
>
> ...Glenn
>
> On 6/25/08, Sathesh Kumar <
sathis...@gmail.com> wrote:
>
>
>
> > C#
>
> > *Iterate through Radio Button controls in panel using Foreach*
> > **
> > *Here is my code *
> > **
>
> > foreach(RadioButton c in pnlradio.Controls)
>
> > {
>
> > if(c.Checked)
>
> > {
>
> > Response.Write(c.Text);
>
> > }
>
> > }
>
> > *Error Message*
>
> > System.InvalidCastException: Specified cast is not valid**