Solved

ASP Repeater ItemDataBound : Getting ImageButton

Posted on 2010-08-16
3
1,229 Views
Last Modified: 2012-05-10
I have the following repeater:


<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="Repeater_ItemDataBound">
    <HeaderTemplate>
      <ul id="navbar">
    </HeaderTemplate>
    <ItemTemplate>
      <li><span>
          <asp:ImageButton ID="imgButton" ImageUrl='<%# Bind("Image") %>' runat="server" PostBackUrl='<%# Bind("Path") %>'
            AlternateText='<%# Bind("AltText") %>' CssClass='<%# Bind("Clicked") %>' /></span>
      </li>
    </ItemTemplate>
    <FooterTemplate>
      </ul>
    </FooterTemplate>
</asp:Repeater>

My ImageButton doesn't have a unique ID for each button, so in my ItemDataBound how do I detect my ImageButton so that I can perform some processing on each image button?

Thanks
0
Comment
Question by:directxBOB
3 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 400 total points
ID: 33444345
The ItemDataBound event will give you access to the row being bound. You an use FindControl("imgButton") to retrieve the ImageButton for the current row.
0
 
LVL 1

Assisted Solution

by:revteam
revteam earned 100 total points
ID: 33444360
In VB:
Public Sub Repeater_ItemDataBound(ByVal Sender As Object, ByVal e As RepeaterItemEventArgs) Handles Repeater1.ItemDataBound

  If e.Item.ItemIndex >= 0 Then
   Dim imgButton As ImageButton= CType(e.Item.FindControl("imgButton"), ImageButton)
    If imgButton  isNot NothingThen
      'do your processing
   End If
End If
EndSub

In C#
 protected void Repeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemIndex > 0)
        {

            ImageButton imgButton = (ImageButton)e.Item.FindControl("imgButton");
         if (imgButton  != null)
 {

        //Do your processing
}

}
}
   
0
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 33444376
public void Repeater1_ItemCommand(object s, RepeaterCommandEventArgs e)
{
ImageButton ddl1 = (ImageButton )e.Item.FindControl("imgButton");
}
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now