Accessing a Control inside a Repeater from a code behind file

Discussion in 'ASP .Net' started by Ric, Feb 27, 2004.

  1. Ric

    Ric Guest

    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.
    Ric, Feb 27, 2004
    #1
    1. Advertising

  2. Hi, Ric,

    The following article explains how it is done:

    http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskreferencingcontrolsinwebformspages.asp

    Hope this helps
    Martin
    "Ric" <> wrote in message
    news:...
    > 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, Feb 27, 2004
    #2
    1. Advertising

  3. 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!
    ric carrasquilla, Feb 27, 2004
    #3
  4. Ric

    Ric Guest

    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="EmployeeInfo" OnItemCommand="getActivityList"
    runat="server">

    <itemtemplate>
    <tr bgcolor="#CCCCCC">
    <td><%# Container.DataItem(0)%></td>
    <td><%# Container.DataItem(1)%></td>
    <td><%# Container.DataItem(2)%></td>
    <td><%# Container.DataItem(3)%></td>
    <td><%# Container.DataItem(4)%></td>
    <td><asp:linkbutton Text=<%# Container.DataItem(5)%>
    runat="server"/></td>
    </tr>
    <tr>
    <td><asp:label id="litLabel" Runat="Server" Text="labelti"
    Visible="false"/></td>
    </tr>
    </itemtemplate>

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

    the first Container.DataItem(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
    DataBoundLiteralControl 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.dataitem. 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.
    Ric, Mar 1, 2004
    #4
  5. Hi, Ric,

    You can pass this value in the CommandName or CommandArgument property:

    > <asp:repeater ID="EmployeeInfo" OnItemCommand="getActivityList"
    > runat="server">
    >
    > <itemtemplate>
    > <tr bgcolor="#CCCCCC">
    > <td><%# Container.DataItem(0)%></td>
    > <td><%# Container.DataItem(1)%></td>
    > <td><%# Container.DataItem(2)%></td>
    > <td><%# Container.DataItem(3)%></td>
    > <td><%# Container.DataItem(4)%></td>
    > <td><asp:linkbutton Text='<%# Container.DataItem(5)%>'


    CommandName="ShowDetails"
    CommandArgument='<%# Container.DataItem(0)%>'

    > runat="server"/></td>
    > </tr>
    > <tr>
    > <td><asp:label id="litLabel" Runat="Server" Text="labelti"
    > Visible="false"/></td>
    > </tr>
    > </itemtemplate>


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

    [C#]
    protected void getActivityList(object s, RepeaterCommandEventArgs e)
    {
    if(e.CommandName == "ShowDetails")
    {
    int ID = int.Parse(e.CommandArgument);
    //....
    }
    }

    [VB.NET]
    Protected Sub getActivityList(s As Object, e As RepeaterCommandEventArgs)
    If e.CommandName = "ShowDetails" Then
    Dim ID As Int32 = Int32.Parse(e.CommandArgument)
    '....
    End If
    End Sub

    Hope this helps
    Martin
    Martin Dechev, Mar 1, 2004
    #5
  6. 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
    commandArguments 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!
    ric carrasquilla, Mar 1, 2004
    #6
  7. Hi, ric carrasquilla,

    <snip>

    > just curiously, if u had to send more
    > than one command arguement how would u do that?


    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
    Martin Dechev, Mar 1, 2004
    #7
  8. 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!
    ric carrasquilla, Mar 1, 2004
    #8
  9. Ric

    Monika Mesik Guest

    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" <> wrote in message
    news:OwDRKdX$...
    >
    >
    > 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!
    Monika Mesik, Mar 3, 2004
    #9
  10. ric carrasquilla, Mar 3, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    570
    Alphonse Giambrone
    Jun 28, 2003
  2. keithb
    Replies:
    1
    Views:
    889
    Bruce Barker
    Mar 29, 2006
  3. John

    Non-code behind to code behind

    John, Feb 19, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    466
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 19, 2007
  4. HockeyFan
    Replies:
    1
    Views:
    989
    Masudur
    Jul 4, 2007
  5. Kiran More
    Replies:
    2
    Views:
    308
    Kiran More
    Nov 14, 2006
Loading...

Share This Page