473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

HowTo loop through HTML Table WebControls?

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
Nov 17 '05 #1
3 4287
"Andreas Klemt" <ak******@hotmail.com> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
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
jo***********@surfcontrol.com
Nov 17 '05 #2
Hello John,
and why does this not work?

For Each ctl As Control In Me.Controls ?

Thanks,
Andreas
"John Saunders" <jo***********@surfcontrol.com> schrieb im Newsbeitrag
news:u7*************@TK2MSFTNGP10.phx.gbl...
"Andreas Klemt" <ak******@hotmail.com> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
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
jo***********@surfcontrol.com

Nov 17 '05 #3
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" <ak******@hotmail.com> wrote in message
news:up**************@TK2MSFTNGP12.phx.gbl...
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

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and...
2
by: Simon | last post by:
I've got a webform and many controls on it. I would like to iterate thru the control collection to get all the textboxes control to let me change the text property. Here is my code...for unknown...
2
by: Phil | last post by:
I have an aspx page that contains 5 tables. Each table I have Named tblSection1, tblSection2, tblSection3, tblSection4, tblSection5 respectively and reside in a corresponding panel for collapse and...
1
by: Patrick | last post by:
Problem I have an ASPX file, with a table of 3 columns, 2 rows with a usercontrol in the middle column (in the code snippet stated below, although in reality, the left hand column would also...
33
by: Brian | last post by:
I have a list of plain HTML radio buttons that I want to be able to loop through, get the values from them and insert them into a db. each one should be a separate record... Can anyone please give...
4
by: DEWright_CA | last post by:
Hi Everyone! I am working on a project in C# and have a table the contains state info, plus a variety of other info that I will reference from another dropdown list. How can I do this...
5
by: serge calderara | last post by:
Dear all, I am new in asp.net and prepare myself for exam I still have dificulties to understand the difference between server control and HTML control. Okey things whcih are clear are the fact...
0
by: Mark Harrison | last post by:
HOWTO: Integrating Posgresql queries into an event loop. Mark Harrison mh@pixar.com May 27, 2004 Problem ------- The commonly used postgresql APIs will block until completed.
3
by: Guillaume Hanique | last post by:
Hi, I feel very stupid. I simply want to derive a control from system.web.ui.webcontrols.button and use that on my webform, but I just can't get it done. Can anyone tell me how to do that? I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.