Repeater problems again!

J

Jeff

Hey

asp.net 2.0

I have a repeater control in my webpage (you see my code below). In this
control's ItemDataBound event I set the ImageUrl of a Image object. My
problem is that when I run this webpage it shows only 1 image... -> the
repeater displays 2 rows, but it's only the first row that displays the
image...

I want each repeater row to display it's image, Any ideas what I should do
to fix this?

This is my repeater control in my webpage:
<asp:Repeater ID="rptInbox" runat="server" DataSourceID="odsInbox"
OnItemDataBound="rptInbox_ItemDataBound">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td bgcolor="#CCFFCC">
<%# Eval("Name") %>
<asp:Image ID="photo" runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>

In this ItemDataBound I have this code:
protected void rptInbox_ItemDataBound(object sender, RepeaterItemEventArgs
e) {
System.Web.UI.WebControls.Image img = null;
if (e.Item.ItemType == ListItemType.Item){
img = (System.Web.UI.WebControls.Image)e.Item.FindControl("photo");
img.ImageUrl = "~/images/test.jpeg";
}
}

I know this line "img.ImageUrl = "~/images/test.jpeg";" may look strange,
but I'm hardcoding this now to see if I get the images displayed correctly.
When images are displaying correctly then I will modify that line to display
images dynamica

This is the html source taken from the browser:
<table>
<tr>
<td bgcolor="#CCFFCC">
test1
<img id="ctl00_content_rptInbox_ctl01_photo"
src="../../images/test.jpeg" style="border-width:0px;" />
</td>
</tr>

<tr>
<td bgcolor="#CCFFCC">
test2
<img id="ctl00_content_rptInbox_ctl02_photo" src=""
style="border-width:0px;" />
</td>
</tr>

</table>


lly
 
R

Riki

Jeff said:
Hey

asp.net 2.0

I have a repeater control in my webpage (you see my code below). In
this control's ItemDataBound event I set the ImageUrl of a Image
object. My problem is that when I run this webpage it shows only 1
image... -> the repeater displays 2 rows, but it's only the first row
that displays the image...

I want each repeater row to display it's image, Any ideas what I
should do to fix this?

This is my repeater control in my webpage:
<asp:Repeater ID="rptInbox" runat="server" DataSourceID="odsInbox"
OnItemDataBound="rptInbox_ItemDataBound">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td bgcolor="#CCFFCC">
<%# Eval("Name") %>
<asp:Image ID="photo" runat="server" />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table></FooterTemplate>
</asp:Repeater>

In this ItemDataBound I have this code:
protected void rptInbox_ItemDataBound(object sender,
RepeaterItemEventArgs e) {
System.Web.UI.WebControls.Image img = null;
if (e.Item.ItemType == ListItemType.Item){
img =
(System.Web.UI.WebControls.Image)e.Item.FindControl("photo");
img.ImageUrl = "~/images/test.jpeg"; }
}

I know this line "img.ImageUrl = "~/images/test.jpeg";" may look
strange, but I'm hardcoding this now to see if I get the images
displayed correctly. When images are displaying correctly then I will
modify that line to display images dynamica

This is the html source taken from the browser:
<table>
<tr>
<td bgcolor="#CCFFCC">
test1
<img id="ctl00_content_rptInbox_ctl01_photo"
src="../../images/test.jpeg" style="border-width:0px;" />
</td>
</tr>

<tr>
<td bgcolor="#CCFFCC">
test2
<img id="ctl00_content_rptInbox_ctl02_photo" src=""
style="border-width:0px;" />
</td>
</tr>

</table>


lly

Change
if (e.Item.ItemType == ListItemType.Item){
in:
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem){

It's a classical error, and having only 2 items made it more confusing.
If you would have had 10 items, they would have been alternating.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top