PC Review


Reply
Thread Tools Rate Thread

Dynamic controls

 
 
=?Utf-8?B?Sm9l?=
Guest
Posts: n/a
 
      26th Oct 2004
quick question,
Im using VB.NET
Im creating a checkbox dynamically then I stick it on a panel. I give each
one a unique id example: "chkLONDON"
Dim oObjCheckBox As CheckBox = New CheckBox()

oObjCheckBox.ID = "chk" +
CType(dsCustomer.Tables(0).Rows(iCount).Item("LocName"), String)

oObjCheckBox.Text = CType(dsCustomer.Tables(0).Rows(iCount).Item("LocName"),
String)

pnlLocs.Controls.Add(oObjCheckBox)

My problem now is, how do I see if that value is checked or not from my
code. When I push my submit button I want to check if its cheked or not. I
tried the following but it didn't work.

Dim oObjCheckBox As CheckBox = New CheckBox()

oObjCheckBox.ID = "chkLONDON"

If (oObjCheckBox.Checked) Then

'do some stuff

Else

 
Reply With Quote
 
 
 
 
Sakharam Phapale
Guest
Posts: n/a
 
      26th Oct 2004
Hello Joe,

To use the dynamically created controls you have to get the reference of the
control object.
Here you can do that by iterating through the controls in Panel.

Dim myControl as Control
For each myControl in Panel.Controls
If TypeOf (myControl) Is CheckBox Then
Dim myCheckBox as CheckBox
If myCheckBox.ID="Test" and myCheckBox. myCheckBox.Checked then
'Do your stuff
Exit For
End If
End If
Next

Hopes this will help

Sakharam Phapale


"Joe" <(E-Mail Removed)> wrote in message
news:034D3DB1-12DD-48E0-A37F-(E-Mail Removed)...
> quick question,
> Im using VB.NET
> Im creating a checkbox dynamically then I stick it on a panel. I give

each
> one a unique id example: "chkLONDON"
> Dim oObjCheckBox As CheckBox = New CheckBox()
>
> oObjCheckBox.ID = "chk" +
> CType(dsCustomer.Tables(0).Rows(iCount).Item("LocName"), String)
>
> oObjCheckBox.Text =

CType(dsCustomer.Tables(0).Rows(iCount).Item("LocName"),
> String)
>
> pnlLocs.Controls.Add(oObjCheckBox)
>
> My problem now is, how do I see if that value is checked or not from my
> code. When I push my submit button I want to check if its cheked or not.

I
> tried the following but it didn't work.
>
> Dim oObjCheckBox As CheckBox = New CheckBox()
>
> oObjCheckBox.ID = "chkLONDON"
>
> If (oObjCheckBox.Checked) Then
>
> 'do some stuff
>
> Else
>



 
Reply With Quote
 
Sakharam Phapale
Guest
Posts: n/a
 
      26th Oct 2004
Hi Joe,

I missed one statement so corrected here.

Dim myControl as Control
For each myControl in Panel.Controls
If TypeOf (myControl) Is CheckBox Then
Dim myCheckBox as CheckBox

------------ myCheckBox =
Type(myControl,CheckBox) -----------------------------------

If myCheckBox.ID="Test" and myCheckBox. myCheckBox.Checked then
'Do your stuff
Exit For
End If
End If
Next


"Sakharam Phapale" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello Joe,
>
> To use the dynamically created controls you have to get the reference of

the
> control object.
> Here you can do that by iterating through the controls in Panel.
>
> Dim myControl as Control
> For each myControl in Panel.Controls
> If TypeOf (myControl) Is CheckBox Then
> Dim myCheckBox as CheckBox



myCheckBox = CType(myControl,CheckBox)


> If myCheckBox.ID="Test" and myCheckBox. myCheckBox.Checked then
> 'Do your stuff
> Exit For
> End If
> End If
> Next
>
> Hopes this will help
>
> Sakharam Phapale
>
>
> "Joe" <(E-Mail Removed)> wrote in message
> news:034D3DB1-12DD-48E0-A37F-(E-Mail Removed)...
> > quick question,
> > Im using VB.NET
> > Im creating a checkbox dynamically then I stick it on a panel. I give

> each
> > one a unique id example: "chkLONDON"
> > Dim oObjCheckBox As CheckBox = New CheckBox()
> >
> > oObjCheckBox.ID = "chk" +
> > CType(dsCustomer.Tables(0).Rows(iCount).Item("LocName"), String)
> >
> > oObjCheckBox.Text =

> CType(dsCustomer.Tables(0).Rows(iCount).Item("LocName"),
> > String)
> >
> > pnlLocs.Controls.Add(oObjCheckBox)
> >
> > My problem now is, how do I see if that value is checked or not from my
> > code. When I push my submit button I want to check if its cheked or

not.
> I
> > tried the following but it didn't work.
> >
> > Dim oObjCheckBox As CheckBox = New CheckBox()
> >
> > oObjCheckBox.ID = "chkLONDON"
> >
> > If (oObjCheckBox.Checked) Then
> >
> > 'do some stuff
> >
> > Else
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Wizard with Dynamic Validation Controls =?Utf-8?B?U3RldmUgRnVuaw==?= Microsoft ASP .NET 0 13th Oct 2006 06:40 PM
Dynamic Controls created by Dynamic Controls Ronald Microsoft ASP .NET 2 17th Jan 2006 12:44 AM
Dynamic Events from Dynamic Controls on a User Control - Guess What? Broken! mytestemailaccount@gmail.com Microsoft ASP .NET 5 23rd Mar 2005 05:06 PM
URGENT: Dynamic controls and dynamic events Mustafa Rabie Microsoft C# .NET 0 22nd Jul 2004 11:35 AM
Repeater, Panel, dynamic user control - can't retrieve dynamic controls in code behind theComputer7 Microsoft C# .NET 2 23rd Jun 2004 04:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:16 PM.