How to write asp.net sintax in C#

Feb 7 2008 8:52 PM

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 databse. 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.

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.

Thanks,

Eduardo

Thanks,

Answers (2)