Accessing a Control inside a Repeater from a code behind file

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

    Accessing a Control inside a Repeater from a code behind file

    im new to asp.net. please help if u can.
    is it possible to refer to a control(ie lable, placeholder, textbox)
    that is inside a repeater object from a code behind file? when i place
    the control object outside of the repeater, i can refer to it from the
    code behind file. when i place the control object inside the repeater,
    i get a 'need to instanciate the control object' error. if i declare
    the control object inside the control behind file, the error goes
    away, but i cant refer to the control objects components. please help.
  • Martin Dechev

    #2
    Re: Accessing a Control inside a Repeater from a code behind file

    Hi, Ric,

    The following article explains how it is done:

    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


    Hope this helps
    Martin
    "Ric" <djscratchnsnif fing@yahoo.com> wrote in message
    news:781ddcc1.0 402271006.6364f ae8@posting.goo gle.com...[color=blue]
    > im new to asp.net. please help if u can.
    > is it possible to refer to a control(ie lable, placeholder, textbox)
    > that is inside a repeater object from a code behind file? when i place
    > the control object outside of the repeater, i can refer to it from the
    > code behind file. when i place the control object inside the repeater,
    > i get a 'need to instanciate the control object' error. if i declare
    > the control object inside the control behind file, the error goes
    > away, but i cant refer to the control objects components. please help.[/color]


    Comment

    • ric carrasquilla

      #3
      Re: Accessing a Control inside a Repeater from a code behind file



      thx martin. i really appreciate the help. i'll bookmark this site.

      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Ric

        #4
        Re: Accessing a Control inside a Repeater from a code behind file

        thx again for the help martin. i was able to use your suggestion to
        get to the control within the repeater. also, i was able to understand
        a bit more bout objects, events and arguments. but, im sure i have a
        lot to more to learn.

        if u or someone else can help me with another question, please do.

        i have a repeater pulling job information from a database. each
        repeater itemtemplate has with a linkbutton and a row with a label
        (for now).

        <asp:repeater ID="EmployeeInf o" OnItemCommand=" getActivityList "
        runat="server">

        <itemtemplate >
        <tr bgcolor="#CCCCC C">
        <td><%# Container.DataI tem(0)%></td>
        <td><%# Container.DataI tem(1)%></td>
        <td><%# Container.DataI tem(2)%></td>
        <td><%# Container.DataI tem(3)%></td>
        <td><%# Container.DataI tem(4)%></td>
        <td><asp:linkbu tton Text=<%# Container.DataI tem(5)%>
        runat="server"/></td>
        </tr>
        <tr>
        <td><asp:labe l id="litLabel" Runat="Server" Text="labelti"
        Visible="false"/></td>
        </tr>
        </itemtemplate>

        when u click on the linkbutton, the label(eventuall y it will be a
        placeholder with more database info in another repeater) will become
        visible with detailed info bout the job.

        the first Container.DataI tem(0) has an ID number that I need to
        extract and send to the stored procedure. how can i extract that
        dataItem. ive been able to loop throw the items in the repeater item
        and extract the entire row. i tried to convert that info to a
        DataBoundLitera lControl and pull the text from it. but when i tried to
        use string functions to pull the ID number or even get a length of
        string i could not consistently get what i needed. i figured out that
        row is coded with <html> table and row tags. thus, im back to trying
        to get the data from the first container.datai tem. so, to make a long
        request even longer, what object or class do i use to pull individual
        dataitems from an item. i looked at the dataitem property from
        repeateritem class, but i cant get it to work. again, thx for the
        help.

        Comment

        • Martin Dechev

          #5
          Re: Accessing a Control inside a Repeater from a code behind file

          Hi, Ric,

          You can pass this value in the CommandName or CommandArgument property:
          [color=blue]
          > <asp:repeater ID="EmployeeInf o" OnItemCommand=" getActivityList "
          > runat="server">
          >
          > <itemtemplate >
          > <tr bgcolor="#CCCCC C">
          > <td><%# Container.DataI tem(0)%></td>
          > <td><%# Container.DataI tem(1)%></td>
          > <td><%# Container.DataI tem(2)%></td>
          > <td><%# Container.DataI tem(3)%></td>
          > <td><%# Container.DataI tem(4)%></td>
          > <td><asp:linkbu tton Text='<%# Container.DataI tem(5)%>'[/color]

          CommandName="Sh owDetails"
          CommandArgument ='<%# Container.DataI tem(0)%>'
          [color=blue]
          > runat="server"/></td>
          > </tr>
          > <tr>
          > <td><asp:labe l id="litLabel" Runat="Server" Text="labelti"
          > Visible="false"/></td>
          > </tr>
          > </itemtemplate>[/color]

          If the ID is an integer you will have to parse it:

          [C#]
          protected void getActivityList (object s, RepeaterCommand EventArgs e)
          {
          if(e.CommandNam e == "ShowDetail s")
          {
          int ID = int.Parse(e.Com mandArgument);
          //....
          }
          }

          [VB.NET]
          Protected Sub getActivityList (s As Object, e As RepeaterCommand EventArgs)
          If e.CommandName = "ShowDetail s" Then
          Dim ID As Int32 = Int32.Parse(e.C ommandArgument)
          '....
          End If
          End Sub

          Hope this helps
          Martin


          Comment

          • ric carrasquilla

            #6
            Re: Accessing a Control inside a Repeater from a code behind file


            thx again for the help martin. just curiously, if u had to send more
            than one command arguement how would u do that? i used a commandName and
            commandArgument and wondered what would u do to send two
            commandArgument s with one commandName or two commandNames each with a
            commandArgument .

            thx again for the push in the right direction.


            *** Sent via Developersdex http://www.developersdex.com ***
            Don't just participate in USENET...get rewarded for it!

            Comment

            • Martin Dechev

              #7
              Re: Accessing a Control inside a Repeater from a code behind file

              Hi, ric carrasquilla,

              <snip>
              [color=blue]
              > just curiously, if u had to send more
              > than one command arguement how would u do that?[/color]

              You normally don't need to do that. The common design is to identify your
              objects with a single identifier. It is possible to pass 2 parameters
              anyway - one for the action and another for the object identifier. This is
              how it was designed, this is how it works and I believe it is enough for any
              case.

              Greetings
              Martin


              Comment

              • ric carrasquilla

                #8
                Re: Accessing a Control inside a Repeater from a code behind file



                thx again martin. i really appreciate the time and thoroughness of your
                answers. have a good day.

                ric

                *** Sent via Developersdex http://www.developersdex.com ***
                Don't just participate in USENET...get rewarded for it!

                Comment

                • Monika Mesik

                  #9
                  Re: Accessing a Control inside a Repeater from a code behind file

                  I'd like to know which site helped to answer the question. I have a similar
                  issue. Can you provide the link?

                  TIA


                  "ric carrasquilla" <djscratchnsnif fing@yahoo.com> wrote in message
                  news:OwDRKdX$DH A.1796@TK2MSFTN GP12.phx.gbl...[color=blue]
                  >
                  >
                  > thx martin. i really appreciate the help. i'll bookmark this site.
                  >
                  > *** Sent via Developersdex http://www.developersdex.com ***
                  > Don't just participate in USENET...get rewarded for it![/color]


                  Comment

                  • ric carrasquilla

                    #10
                    Re: Accessing a Control inside a Repeater from a code behind file



                    this is the link to how to find an object inside a repeater


                    tml/vbtskreferencin gcontrolsinwebf ormspages.asp

                    i hope this helps. also, if u look at the thread, martin explains how
                    to send a commandname and command argument to the repeatercommand event

                    please reply to this thread for more help.

                    *** Sent via Developersdex http://www.developersdex.com ***
                    Don't just participate in USENET...get rewarded for it!

                    Comment

                    Working...