Professional Web Applications Themes

HowTo loop through HTML Table WebControls? - ASP.NET General

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...

  1. #1

    Default 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


    Andreas Guest

  2. #2

    Default Re: HowTo loop through HTML Table WebControls?

    "Andreas Klemt" <com> wrote in message
    news:phx.gbl... 

    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
    com


    John Guest

  3. #3

    Default Re: HowTo loop through HTML Table WebControls?

    Hello John,
    and why does this not work?

    For Each ctl As Control In Me.Controls ?

    Thanks,
    Andreas


    "John Saunders" <com> schrieb im Newsbeitrag
    news:phx.gbl... 
    >
    > Andreas,
    >
    > If you looked, you'd see what the type of the one control is. That will[/ref]
    tell 


    Andreas Guest

  4. #4

    Default Re: HowTo loop through HTML Table WebControls?

    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/security_bulletins/ms03-026.asp



    "Andreas Klemt" <com> wrote in message
    news: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



    Ken Guest

Similar Threads

  1. Need to update other WebControls when switching from html to design view
    By robert.minter@tallan.com in forum ASP.NET Building Controls
    Replies: 2
    Last Post: July 21st, 01:50 AM
  2. Howto loop through table cells in a selection
    By Roger_Pearse in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 3
    Last Post: March 23rd, 10:42 PM
  3. HOWTO? Make a table in a db from a dataset
    By Dave in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: March 6th, 03:36 AM
  4. Howto reference non-webcontrols on an ASPX page?
    By Gergely Varadi in forum ASP.NET Building Controls
    Replies: 0
    Last Post: September 22nd, 04:19 PM
  5. Inheriting from System.Web.UI.WebControls.Table
    By Jimmy [Used-Disks] in forum ASP.NET Building Controls
    Replies: 1
    Last Post: August 14th, 06:32 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139