Solved

ASP Repeater ItemDataBound : Getting ImageButton

Posted on 2010-08-16
3
1,255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

752 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