Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataBinder MindBender in Image Button inside a repeater Control

Status
Not open for further replies.

wbochar

IS-IT--Management
Mar 14, 2003
72
US
The problem at hand is that I have a Repeater control looping through a sql table creating image buttons. In the aspx file I have a databinder pulling the image location, but it keeps dumping the text as a literal text chunk as opposed to data fromthe database..

Code:
<asp:Repeater id="RepeaterIcon" runat="server">
<HeaderTemplate>
<table align="left"><tr>
</HeaderTemplate>
<ItemTemplate>
<td>
<asp:ImageButton Runat=server ImageUrl='../images/icons/<%#DataBinder.Eval(Container.DataItem, "ICON_FILENAME")%>' ID='ICON'></asp:ImageButton>
<%# DataBinder.Eval(Container.DataItem, "ICON_FILENAME") %>
</td>
</ItemTemplate>
<FooterTemplate>
</tr></table>
</FooterTemplate>
</asp:Repeater>

The databinder outside the imagebutton references the DB item properly but when I look at the code for the img url that gets generated I get:

Code:
<td>
<input type="image" name="RepeaterIcon:_ctl5:ICON" id="RepeaterIcon__ctl5_ICON" src="../images/icons/<%#DataBinder.Eval(Container.DataItem, &quot;ICON_FILENAME&quot;)%>" border="0" />
CV5.JPG
</td>

If I remove the the '../images/icons/' part of the imagbutton code the data gets gets loaded correctly (but since it doesnt have the right folder there the image doesnt show up)..

I know it has to do with how <%# %> is dumping the text so how I get it dump data and not written literally..

Any thoughts?

wbochar
 
I almost never use the <%# %> syntax within itemtemplates anymore, but opt for the more control you get by catchin the ItemDataBound event and setting the properties of the items there.

Your repeater has an ItemDataBound event which is fired every time another row from your query gets put into the repeater. During that event you can do as much code as you want without being confined to the contraints of the <%# %> tags.

In the html, just put in the bare essentials of the controls you 'll need. -
Code:
<ItemTemplate>
    <asp:ImageButton id="imgBtn" runat="server" />
</ItemTemplate>
Now you could get a reference to the ImageButton in the item being bound each time during the ItemDataBound event

Code:
ImageButton myImageButton = (ImageButton)e.Item.Findcontrol("imgBtn");

myImageButton.ImageUrl = "imageUrl from database";



Greetings,
Dragonwell
 
What about when you are creating a stack of image controls?
 
I wasn't that Clear with my last post..

What happens if I created 12 controls, how would I be able to access each by name? if there was 12 records in my DB and the Repeater made 12 imagebuttons how would I access each to add the imageurl onto it? I tried messing around with the code you gave me but I can't seem to get ito go..

wbochar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top