Forums

ASP

This topic is locked

Please help!

Posted 08 Feb 2008 04:32:19
1
has voted
08 Feb 2008 04:32:19 Eduardo arias posted:
Hello!

I have a code in Asp.net that calls a method in the code behind:

ASP.NET Code:
<img src="<%#CheckImage() %>" />

The objective of the following code is to check if an image exists in the database. I have created a method in the code behind(c#) that would check the image field in the database (ImageURL), if it is there, then the method should tell the ASP.net code to place the image in the browser. However, if it is not there, then the image is ignored. I just don't know how to tell the asp.net from c# to execute the code. I'm using a boolean, and I'm not sure if this is correct, in fact, I don't think it make any sense to have a boolean value.

C# Code:

public bool CheckImage()
{

OleDbConnection objConn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=c:\\Louis\\Louis.mdb";OleDbCommand objCmd = new OleDbCommand("select * from WhiteHouse", objConn);
objConn.Open();

OleDbDataReader objRdr = objCmd.ExecuteReader();

while (objRdr.Read())
{

if (objRdr["ImageURL"] != null)
{

//For example <Img src="<%# DataBind.Eval(Container.DataItem, "ImageURL" %>

//meaning, go to the asp code and get the image to place it in the browser

return true;
}

else

{

//meaning, don't get the image

return false;
}

}

}

I would greatly appreciate some help.



Thank you,

Eduardo

Reply to this topic