By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,573 Members | 3,017 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,573 IT Pros & Developers. It's quick & easy.

Repeater problems again!

P: n/a
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.FindContro l("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
Jul 3 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Jeff wrote:
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.FindContro l("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.

--

Riki
Jul 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.