Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > HowTo loop through HTML Table WebControls?

Reply
Thread Tools

HowTo loop through HTML Table WebControls?

 
 
Andreas Klemt
Guest
Posts: n/a
 
      08-22-2003
Hello,
I have this:

<table id="myTable" runat="server">
<tr>
<td><asp:label id="lblText" runat="server"></asp:label>
<asp:button id="btn1" runat="server"></asp:button>
<asp:button id="btn2" runat="server"></asp:button>
<asp:button id="btn3" runat="server"></asp:button>
</td>
</tr>
</table>


Now I want to loop through like this:

For Each ctl As Control In Me.myTable.Controls
If TypeOf ctl Is Button Then
CType(ctl, Button).Enabled = False
End If
Next

But this doesn't work because in Me.myTable.Controls
there is only 1 Control. Why is this wrong and what is the correct way?

Thanks in advance,
Andreas


 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      08-22-2003
"Andreas Klemt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
> I have this:
>
> <table id="myTable" runat="server">
> <tr>
> <td><asp:label id="lblText" runat="server"></asp:label>
> <asp:button id="btn1" runat="server"></asp:button>
> <asp:button id="btn2" runat="server"></asp:button>
> <asp:button id="btn3" runat="server"></asp:button>
> </td>
> </tr>
> </table>
>
>
> Now I want to loop through like this:
>
> For Each ctl As Control In Me.myTable.Controls
> If TypeOf ctl Is Button Then
> CType(ctl, Button).Enabled = False
> End If
> Next
>
> But this doesn't work because in Me.myTable.Controls
> there is only 1 Control. Why is this wrong and what is the correct way?


Andreas,

If you looked, you'd see what the type of the one control is. That will tell
you what's going on.
--
John Saunders
Internet Engineer
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
 
Andreas Klemt
Guest
Posts: n/a
 
      08-22-2003
Hello John,
and why does this not work?

For Each ctl As Control In Me.Controls ?

Thanks,
Andreas


"John Saunders" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed)...
> "Andreas Klemt" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hello,
> > I have this:
> >
> > <table id="myTable" runat="server">
> > <tr>
> > <td><asp:label id="lblText" runat="server"></asp:label>
> > <asp:button id="btn1" runat="server"></asp:button>
> > <asp:button id="btn2" runat="server"></asp:button>
> > <asp:button id="btn3" runat="server"></asp:button>
> > </td>
> > </tr>
> > </table>
> >
> >
> > Now I want to loop through like this:
> >
> > For Each ctl As Control In Me.myTable.Controls
> > If TypeOf ctl Is Button Then
> > CType(ctl, Button).Enabled = False
> > End If
> > Next
> >
> > But this doesn't work because in Me.myTable.Controls
> > there is only 1 Control. Why is this wrong and what is the correct way?

>
> Andreas,
>
> If you looked, you'd see what the type of the one control is. That will

tell
> you what's going on.
> --
> John Saunders
> Internet Engineer
> (E-Mail Removed)
>
>



 
Reply With Quote
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      08-22-2003
It would be better to keep a question to one newsgroup. Here's the answer I
posted in the other group:

Don't forget that your buttons are inside a table which has its own controls,
so you have to dig a little deeper before you start looping for the buttons.
You might want to use FindControl to get closer to the action.

It helps to turn tracing on in a page to see where controls are really nested.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ctl As Control
Dim btn As System.Web.UI.WebControls.Button
For Each ctl In myTable.Controls(0).Controls(0).Controls
If TypeOf ctl Is System.Web.UI.WebControls.Button Then
btn = ctl
btn.Enabled = False
End If
Next
End Sub

Does this help>

Ken MVP [ASP.NET]


--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
http://www.microsoft.com/security/se...s/ms03-026.asp



"Andreas Klemt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
Hello,
I have this:

<table id="myTable" runat="server">
<tr>
<td><asp:label id="lblText" runat="server"></asp:label>
<asp:button id="btn1" runat="server"></asp:button>
<asp:button id="btn2" runat="server"></asp:button>
<asp:button id="btn3" runat="server"></asp:button>
</td>
</tr>
</table>


Now I want to loop through like this:

For Each ctl As Control In Me.myTable.Controls
If TypeOf ctl Is Button Then
CType(ctl, Button).Enabled = False
End If
Next

But this doesn't work because in Me.myTable.Controls
there is only 1 Control. Why is this wrong and what is the correct way?

Thanks in advance,
Andreas



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Re: How to loop through a list while inside the loop, the list size may be decreased? Roedy Green Java 3 09-13-2008 01:51 AM
Howto Listen html link clicks and change them in STATIC HTML pages..... Aykut Canturk ASP .Net 2 06-04-2008 11:31 AM
convert html to web controls so I can loop through them on the code behind.. Hazzard ASP .Net Web Controls 3 04-26-2004 03:02 AM
loop through rows in a table Fraggle ASP .Net 3 11-24-2003 04:23 PM



Advertisments