Image Not Showing

I

Iain

Hi

I am using Borland Developer 2006 (C# code behind) to create a 3
Column CSS app. Fairly new to the .net platform and very new to
repeaters.

I have 2 repeaters on a page, both of which are filled from a
database. The Links in the left hand column are created correctly and
displayed. The images/Links (hrefs) in the right hand column are the
problem. The links are displayed correctly but the images are not
displayed. The html is build dynamically. I have debugged the
application and copied the html that has been built. When I paste it
into the html and run it the images are displayed correctly. It is
driving me nuts. The following is an example of the string that is
built dynamically during the program run..

"<p><ASP:Image id="TheImage1" runat="server" height="80px"
width="140px" imageurl="Images/Image2.jpg" alternatetext = "Google Web
Page"></ASP:Image><br><a href="http://www.google.co.uk">Google</a></
p>"

In all cases the images exist.

Can anyone please help ?

Thanks in advance for any assistance offered.

Iain

===============================================

<html>
<head>
<title>My Title</title>
<meta http-equiv="content-type" content="text/html;
charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="CSS/
Standard.css" />
</head>
<body>

<div id="content">
<h1>My Title</h1>
<p>This is The Main Body Of The Page</p>

</div>
<!-- The following is the left hand column. It is built mainly
from a table of links from a database table -->
<div id="side1">
<h4>Search Our Pages</h4>
<form method="post" action="">
<input class="inputBox" name="textfield"
class="inputBox" /> said:
<br /><br />
</form>
<!-- The first repeater -->
<p>
<asp:Repeater id="Repeater1"
OnItemCreated="R1_ItemCreated"
runat="server">
<ItemTemplate><%#
DataBinder.Eval(Container.DataItem, "Ticker") %>
</ItemTemplate>
</asp:Repeater>
</p>

<!-- The right hand column. It is built mainly from a table of
Images/Links from a database table -->
<!-- This is where the problem lies. The links are displayed
but the images are not -->
</div>
<div id="side2" border="1">
<p>
<asp:Repeater id="Repeater2"
OnItemCreated="R1_ItemCreated"
runat="server">
<ItemTemplate><%#
DataBinder.Eval(Container.DataItem, "Ticker") %>
</ItemTemplate>
</asp:Repeater>
</p>
</div>
</body>
</html>

The code behind is

protected void R1_ItemCreated(Object Sender,
RepeaterItemEventArgs
e)
{
String iTypeText = "";

switch (e.Item.ItemType) {
case ListItemType.Item:
iTypeText = "Item";
break;
case ListItemType.AlternatingItem:
iTypeText =
"AlternatingItem";
break;
case ListItemType.Header:
iTypeText = "Header";
break;
case ListItemType.Footer:
iTypeText = "Footer";
break;
case ListItemType.Separator:
iTypeText =
"Separator";
break;
}
}

public class PositionData
{

private string ticker;

public PositionData(string name, string
ticker, string PType,
string PImageId, string PTheImageName, string TheAlternateText, string
PTheImageText, string PHRef)
{
this.ticker = "";
if (PType == "Link")
{
this.ticker = "<li><a href=" +
ticker.Trim() + ">" + name.Trim()
+ "</a></li>";
};
if (PType == "AdBox")
{
this.ticker = "<p><ASP:Image
id=\"" + PImageId + "\" runat=\"server\" height=\"80px\" width=
\"140px
\" imageurl=\"" + PTheImageName + "\" alternatetext = \"" +
TheAlternateText + "\"></ASP:Image><br><a href=\"" + PHRef + "\">" +
PTheImageText + "</a></p>";
};
}

public string Ticker
{
get
{
return ticker;
}
}
}

private void Page_Load(object sender, System.EventArgs
e)
{
string LLabel = "";
ArrayList values = new ArrayList();

OleDbConnection con = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" +
Server.MapPath("Databases/TestDB.mdb"));

OleDbCommand cmd = new OleDbCommand();

string LSqlString = "Select * From Links";
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = LSqlString;
OleDbDataReader reader = cmd.ExecuteReader();
LLabel = "<ul>";
values.Add(new PositionData(LLabel, "", "","",
"", "", "", ""));
while (reader.Read())
{
string LFormName =
reader[0].ToString();
string LSection =
reader[1].ToString();
string LLinkName =
reader[2].ToString();
string LLink = reader[3].ToString();
values.Add(new PositionData(LLinkName,
LLink, "Link","", "", "",
"", ""));
}
LLabel = "</ul>";
values.Add(new PositionData(LLabel, "", "","",
"", "", "", ""));
Repeater1.DataSource = values;
Repeater1.DataBind();

con.Close();

values.Clear();

LSqlString = "Select * From Images";
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = LSqlString;
OleDbDataReader reader2 = cmd.ExecuteReader();

int LCounter = 1;
LLabel = "<div class=\"adbox\">";
values.Add(new PositionData(LLabel, "", "","",
"", "", "", ""));

while (reader2.Read())
{
string ImageFormName =
reader2[0].ToString();
string ImageSection =
reader2[1].ToString();
string TheImageText =
reader2[2].ToString();
string TheImageName =
reader2[3].ToString();
string TheAlternatetext =
reader2[4].ToString();
string TheHRef =
reader2[5].ToString();
values.Add(new PositionData("", "",
"AdBox", "TheImage" +
LCounter.ToString(), TheImageName, TheAlternatetext, TheImageText,
TheHRef));
}
Repeater2.DataSource = values;
Repeater2.DataBind();

LLabel = "<\\div>" ;
values.Add(new PositionData(LLabel, "", "","",
"", "", "", ""));

con.Close();

}
 

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,985
Messages
2,570,199
Members
46,766
Latest member
rignpype

Latest Threads

Top