0

I'm creating a repeater. This is shown below

<asp:Repeater runat="server" ID="repeaterEvent" OnItemCommand="repeaterEvent_ItemCommand">
                        <ItemTemplate>
                            <div class="jumbotron">
                                <h4><asp:Label ID="Label2" runat="server" Text='<%#Bind("EvtDescription") %>'></asp:Label></h4>   
                                <h4><asp:Label runat="server">Amount Attending: </asp:Label>       
                                <asp:Label ID="Label4" runat="server" Text='<%#Bind("EvtVote") %>'></asp:Label></h4>
                                <asp:Button runat="server" ID="eventButton" Text="Attending" class="btn btn-primary" CommandName="Vote"/>
                            </div>
                        </ItemTemplate>
                    </asp:Repeater>

I've also got an image with the code for it below:

<img runat="server" id="imageTest" src="imageIDtagName" />

Back end code:

imageTest.Src = "data:Image/png;base64," + str;

This works perfectly well and I'm able to display the image. The problem occurs when I try to add this line of code within the repeater. The error says "The name 'imageTest' does not exist in the current context. I'm sure this is a simple problem but thanks in advance

Stuart
  • 143
  • 1
  • 3
  • 18

1 Answers1

0

As child controls will be created for each item in bound data, while referring to child control, you will have to refer through item collection. Also, for data bound controls, you will need to use FindControl method to refer child controls. You can use ItemDataBound event to get the image control by following code:

 protected void repeaterEvent_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
(e.Item.FindControl("imageTest") as HtmlImage).Src = "data:Image/png;base64," + str;
}
user952125
  • 61
  • 1
  • 2