HowTo loop through HTML Table WebControls?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andreas Klemt

    #1

    HowTo loop through HTML Table WebControls?

    Hello,
    I have this:

    <table id="myTable" runat="server">
    <tr>
    <td><asp:labe l 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.Cont rols
    If TypeOf ctl Is Button Then
    CType(ctl, Button).Enabled = False
    End If
    Next

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

    Thanks in advance,
    Andreas


  • John Saunders

    #2
    Re: HowTo loop through HTML Table WebControls?

    "Andreas Klemt" <aklemt68@hotma il.com> wrote in message
    news:upK5THEaDH A.2024@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hello,
    > I have this:
    >
    > <table id="myTable" runat="server">
    > <tr>
    > <td><asp:labe l 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.Cont rols
    > If TypeOf ctl Is Button Then
    > CType(ctl, Button).Enabled = False
    > End If
    > Next
    >
    > But this doesn't work because in Me.myTable.Cont rols
    > there is only 1 Control. Why is this wrong and what is the correct way?[/color]

    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
    john.saunders@s urfcontrol.com


    Comment

    • Andreas Klemt

      #3
      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" <john.saunders@ surfcontrol.com > schrieb im Newsbeitrag
      news:u7PGcOEaDH A.628@TK2MSFTNG P10.phx.gbl...[color=blue]
      > "Andreas Klemt" <aklemt68@hotma il.com> wrote in message
      > news:upK5THEaDH A.2024@TK2MSFTN GP12.phx.gbl...[color=green]
      > > Hello,
      > > I have this:
      > >
      > > <table id="myTable" runat="server">
      > > <tr>
      > > <td><asp:labe l 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.Cont rols
      > > If TypeOf ctl Is Button Then
      > > CType(ctl, Button).Enabled = False
      > > End If
      > > Next
      > >
      > > But this doesn't work because in Me.myTable.Cont rols
      > > there is only 1 Control. Why is this wrong and what is the correct way?[/color]
      >
      > Andreas,
      >
      > If you looked, you'd see what the type of the one control is. That will[/color]
      tell[color=blue]
      > you what's going on.
      > --
      > John Saunders
      > Internet Engineer
      > john.saunders@s urfcontrol.com
      >
      >[/color]


      Comment

      • Ken Cox [Microsoft MVP]

        #4
        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.EventArg s) Handles MyBase.Load
        Dim ctl As Control
        Dim btn As System.Web.UI.W ebControls.Butt on
        For Each ctl In myTable.Control s(0).Controls(0 ).Controls
        If TypeOf ctl Is System.Web.UI.W ebControls.Butt on 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" <aklemt68@hotma il.com> wrote in message
        news:upK5THEaDH A.2024@TK2MSFTN GP12.phx.gbl...
        Hello,
        I have this:

        <table id="myTable" runat="server">
        <tr>
        <td><asp:labe l 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.Cont rols
        If TypeOf ctl Is Button Then
        CType(ctl, Button).Enabled = False
        End If
        Next

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

        Thanks in advance,
        Andreas



        Comment

        Working...