How do I loop this in a FOR loop

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?aUhhdkFRdWVzdGlvbg==?=

    How do I loop this in a FOR loop

    I have a textbox control in each row of the table and I need to display it
    dynamically
    In the first row of the table it is txtSample1 and in the second row it is
    txtSample2

    The below code is not working

    for (int i = 0; i < ddlHowMany.Sele ctedIndex ; i++)
    {
    UserTable.Rows[i].FindControl("( txtSample)+(i)" ).Visible = true;
    }

    Plz help me out..

  • Mark Rae [MVP]

    #2
    Re: How do I loop this in a FOR loop

    "iHavAQuest ion" <iHavAQuestion@ discussions.mic rosoft.comwrote in message
    news:FBD2DD26-C9A3-4019-8658-C3601CE3D5FC@mi crosoft.com...
    In the first row of the table it is txtSample1
    The below code is not working
    >
    for (int i = 0; i < ddlHowMany.Sele ctedIndex ; i++)
    {
    UserTable.Rows[i].FindControl("( txtSample)+(i)" ).Visible = true;
    }
    >
    Plz help me out..
    First time round, the code is looking for a control called txtSample0 which,
    as you have described it, won't exist...


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • =?Utf-8?B?aUhhdkFRdWVzdGlvbg==?=

      #3
      Re: How do I loop this in a FOR loop

      Though I start from one the following code dosent work
      UserTable.Rows[i].FindControl("( txtSample)+(i)" ).Visible = true;

      I am not able to concatinate txtSample with " i " in the loop.

      Any gusses.




      "Mark Rae [MVP]" wrote:
      "iHavAQuest ion" <iHavAQuestion@ discussions.mic rosoft.comwrote in message
      news:FBD2DD26-C9A3-4019-8658-C3601CE3D5FC@mi crosoft.com...
      >
      In the first row of the table it is txtSample1
      >
      The below code is not working

      for (int i = 0; i < ddlHowMany.Sele ctedIndex ; i++)
      {
      UserTable.Rows[i].FindControl("( txtSample)+(i)" ).Visible = true;
      }

      Plz help me out..
      >
      First time round, the code is looking for a control called txtSample0 which,
      as you have described it, won't exist...
      >
      >
      --
      Mark Rae
      ASP.NET MVP

      >
      >

      Comment

      • David

        #4
        Re: How do I loop this in a FOR loop

        UserTable.Rows[i].FindControl("t xtSample" + i).Visible = true;

        Your txtSample was inside brackets and the whole lot was inside quotes, so
        you were literally looking for a control called (txtSample)+(i)



        --
        Best regards,
        Dave Colliver.

        ~~
        http://www.FOCUSPortals.com - Local franchises available
        "iHavAQuest ion" <iHavAQuestion@ discussions.mic rosoft.comwrote in message
        news:3D777F62-3313-404B-8469-2C47E0BBD018@mi crosoft.com...
        Though I start from one the following code dosent work
        UserTable.Rows[i].FindControl("( txtSample)+(i)" ).Visible = true;
        >
        I am not able to concatinate txtSample with " i " in the loop.
        >
        Any gusses.
        >
        >
        >
        >
        "Mark Rae [MVP]" wrote:
        >
        >"iHavAQuestion " <iHavAQuestion@ discussions.mic rosoft.comwrote in
        >message
        >news:FBD2DD2 6-C9A3-4019-8658-C3601CE3D5FC@mi crosoft.com...
        >>
        In the first row of the table it is txtSample1
        >>
        The below code is not working
        >
        for (int i = 0; i < ddlHowMany.Sele ctedIndex ; i++)
        {
        UserTable.Rows[i].FindControl("( txtSample)+(i)" ).Visible = true;
        }
        >
        Plz help me out..
        >>
        >First time round, the code is looking for a control called txtSample0
        >which,
        >as you have described it, won't exist...
        >>
        >>
        >--
        >Mark Rae
        >ASP.NET MVP
        >http://www.markrae.net
        >>
        >>

        Comment

        • Peter Bromberg [C# MVP]

          #5
          Re: How do I loop this in a FOR loop

          I'm only guessing that this code will even work (the way you have it) but if
          the first one is "txtSample1 " then you would need this:

          UserTable.Rows[i].FindControl("( txtSample"+(i+1 ).ToString() ).Visible =
          true;

          --Peter

          "iHavAQuest ion" <iHavAQuestion@ discussions.mic rosoft.comwrote in message
          news:FBD2DD26-C9A3-4019-8658-C3601CE3D5FC@mi crosoft.com...
          >I have a textbox control in each row of the table and I need to display it
          dynamically
          In the first row of the table it is txtSample1 and in the second row it is
          txtSample2
          >
          The below code is not working
          >
          for (int i = 0; i < ddlHowMany.Sele ctedIndex ; i++)
          {
          UserTable.Rows[i].FindControl("( txtSample)+(i)" ).Visible = true;
          }
          >
          Plz help me out..
          >

          Comment

          • David

            #6
            Re: How do I loop this in a FOR loop

            You should be ashamed of yourself Peter... you missed a closing bracket
            somewhere... :-)

            (Mind you, it won't actually do anything, as the bracket is inside a quoted
            string, but even then, if it is called txtSample1, it won't be found with
            (txtSample1 as your string. )

            --
            Best regards,
            Dave Colliver.

            ~~
            http://www.FOCUSPortals.com - Local franchises available


            "Peter Bromberg [C# MVP]" <pbromberg@nosp ammaam.yahoo.co mwrote in message
            news:3518932A-91F1-462F-B896-852447941668@mi crosoft.com...
            I'm only guessing that this code will even work (the way you have it) but
            if the first one is "txtSample1 " then you would need this:
            >
            UserTable.Rows[i].FindControl("( txtSample"+(i+1 ).ToString() ).Visible =
            true;
            >
            --Peter
            >
            "iHavAQuest ion" <iHavAQuestion@ discussions.mic rosoft.comwrote in message
            news:FBD2DD26-C9A3-4019-8658-C3601CE3D5FC@mi crosoft.com...
            >>I have a textbox control in each row of the table and I need to display
            >>it
            >dynamically
            >In the first row of the table it is txtSample1 and in the second row it
            >is
            >txtSample2
            >>
            >The below code is not working
            >>
            >for (int i = 0; i < ddlHowMany.Sele ctedIndex ; i++)
            >{
            > UserTable.Rows[i].FindControl("( txtSample)+(i)" ).Visible = true;
            >}
            >>
            >Plz help me out..
            >>
            >

            Comment

            Working...