how to get the control ID embedded in a repeater?

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

    how to get the control ID embedded in a repeater?

    Hi,

    I have a repeater which contains an imagebutton like this:

    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="S qlDataSource1">
    <ItemTemplate >
    <asp:ImageButto n ID="ImageButton 1" runat="server" ImageUrl='<%#
    Eval("myfield", "mf\{0}") %>' " runat="server" />
    </ItemTemplate>
    </asp:Repeater>

    I try to get its id in code-behind; i tried this ithout succes:

    Dim img As ImageButton
    img = Repeater1.FindC ontrol("imagebu tton1")

    Thanks
    Dan


  • Nathan Sokalski

    #2
    Re: how to get the control ID embedded in a repeater?

    First of all, you cannot get the individual IDs until the Repeater is
    DataBound, so the best place to do what you are doing would probably be in
    the ItemDataBound event.

    protected void Repeater1_ItemD ataBound(object sender, RepeaterItemEve ntArgs
    e)

    You would use something like the following:

    img=(ImageButto n)e.Item.FindCo ntrol("ImageBut ton1");
    imgID=img.Clien tId;

    The ItemDataBound event is called once for each record in the DataSource.
    That about as much as I can say with what you've given us, so hopefully you
    can take it from here. Good Luck!
    --
    Nathan Sokalski
    njsokalski@hotm ail.com
    有声小说网为广大读者提供热门小说在线免费阅读,本站收集的网络文学小说情节跌宕起伏,有声小说网是值得书友们收藏的小说在线阅读网。


    "Dan" <nm@zszsz.xvwro te in message
    news:uIZGhqULJH A.456@TK2MSFTNG P06.phx.gbl...
    Hi,
    >
    I have a repeater which contains an imagebutton like this:
    >
    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="S qlDataSource1">
    <ItemTemplate >
    <asp:ImageButto n ID="ImageButton 1" runat="server" ImageUrl='<%#
    Eval("myfield", "mf\{0}") %>' " runat="server" />
    </ItemTemplate>
    </asp:Repeater>
    >
    I try to get its id in code-behind; i tried this ithout succes:
    >
    Dim img As ImageButton
    img = Repeater1.FindC ontrol("imagebu tton1")
    >
    Thanks
    Dan
    >

    Comment

    • George

      #3
      Re: how to get the control ID embedded in a repeater?

      You must understand that when you put your control into Repeater or Grid
      then that control will be repeated many time... once for each record in your
      DataSource.

      After you understand that you will easily understand that code
      img = Repeater1.FindC ontrol("imagebu tton1")
      does not make much sense. Since there are more than one ImageButton1

      There are several solutions depending on what you want to do. If you want to
      modify the image based on the data in a row then you need to subscribe to
      ItemDataBound event.
      That will get you access to particular row during binding. and then using
      FindControl you will be able to find that ImageButton.


      George.


      "Dan" <nm@zszsz.xvwro te in message
      news:uIZGhqULJH A.456@TK2MSFTNG P06.phx.gbl...
      Hi,
      >
      I have a repeater which contains an imagebutton like this:
      >
      <asp:Repeater ID="Repeater1" runat="server" DataSourceID="S qlDataSource1">
      <ItemTemplate >
      <asp:ImageButto n ID="ImageButton 1" runat="server" ImageUrl='<%#
      Eval("myfield", "mf\{0}") %>' " runat="server" />
      </ItemTemplate>
      </asp:Repeater>
      >
      I try to get its id in code-behind; i tried this ithout succes:
      >
      Dim img As ImageButton
      img = Repeater1.FindC ontrol("imagebu tton1")
      >
      Thanks
      Dan
      >

      Comment

      • Dan

        #4
        Re: how to get the control ID embedded in a repeater?

        thanks
        "George" <noemail@comcas t.netschreef in bericht
        news:OOBBtXVLJH A.4708@TK2MSFTN GP02.phx.gbl...
        You must understand that when you put your control into Repeater or Grid
        then that control will be repeated many time... once for each record in
        your DataSource.
        >
        After you understand that you will easily understand that code
        img = Repeater1.FindC ontrol("imagebu tton1")
        does not make much sense. Since there are more than one ImageButton1
        >
        There are several solutions depending on what you want to do. If you want
        to modify the image based on the data in a row then you need to subscribe
        to ItemDataBound event.
        That will get you access to particular row during binding. and then using
        FindControl you will be able to find that ImageButton.
        >
        >
        George.
        >
        >
        "Dan" <nm@zszsz.xvwro te in message
        news:uIZGhqULJH A.456@TK2MSFTNG P06.phx.gbl...
        >Hi,
        >>
        >I have a repeater which contains an imagebutton like this:
        >>
        ><asp:Repeate r ID="Repeater1" runat="server"
        >DataSourceID=" SqlDataSource1" >
        ><ItemTemplat e>
        ><asp:ImageButt on ID="ImageButton 1" runat="server" ImageUrl='<%#
        >Eval("myfield" ,"mf\{0}") %>' " runat="server" />
        ></ItemTemplate>
        ></asp:Repeater>
        >>
        >I try to get its id in code-behind; i tried this ithout succes:
        >>
        >Dim img As ImageButton
        >img = Repeater1.FindC ontrol("imagebu tton1")
        >>
        >Thanks
        >Dan
        >>
        >

        Comment

        Working...