Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1284
  • Last Modified:

ASP Repeater ItemDataBound : Getting ImageButton

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
directxBOB
Asked:
directxBOB
2 Solutions
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
revteamCommented:
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
 
Kamal KhaleefaInformation Security SpecialistCommented:
public void Repeater1_ItemCommand(object s, RepeaterCommandEventArgs e)
{
ImageButton ddl1 = (ImageButton )e.Item.FindControl("imgButton");
}
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now