Right, so I'm pulling information out of a database, by Scheme Code, and displaying it on a webform, where it can be modified or new records can be created. to get the image out I created a Generic handler as a sort of virtual address.
I'm having some trouble passing the dropdownlist.selectedItem.Text
(Which is where you select the Scheme code for the record you want) value into a parameter in the generic handler. I can pass a string directly in and then just choose that particular Scheme code and it all works.
This is the SQL command code
public static TemplateData ReturnData(string schemeCode)
{
string sqlInstructionCstmID = "SELECT TOP(1) LetterTemplateCustomisationId, TemplateId, Logo, SchemeCode, Version, Comment FROM LetterTemplateCustomisation WHERE SchemeCode ='" + schemeCode + "'";
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["LettersDatabase"].ConnectionString;
SqlConnection connect = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(sqlInstructionCstmID, connect);
command.CommandType = CommandType.Text;
connect.Open();
SqlDataReader dr = command.ExecuteReader();
TemplateData tempData = null;
if (dr.HasRows)
{
dr.Read();
tempData = new TemplateData(dr);
}
dr.Close();
connect.Close();
return tempData;
}
The generic handler... with the empty parameters
public class ImageHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
TemplateData imgData = DataClass.ReturnData();
if (imgData != null)
{
context.Response.ContentType = "image/jpeg";
context.Response.BinaryWrite(imgData.Logo);
context.Response.OutputStream.Write(imgData.Logo, 0, imgData.Logo.Length);
context.Response.Flush();
}
}
and this is the code behind
protected void btnSearch_Click(object sender, EventArgs e)
{
if (ddSchemeCode.SelectedIndex > 0)
{
// Existing Data to load from database
TemplateData temp = DataClass.ReturnData(ddSchemeCode.SelectedItem.Text);
if (temp != null)
{
txtVersion.Text = temp.Version;
txtComment.Text = temp.Comment;
txtSchemeCode.Text = temp.SchemeCode;
txtTemplateId.Text = temp.TemplateId;
imgLogo.ImageUrl = "ImageHandler.ashx"
}
}
so it's the empty parameter in TemplateData imgData = DataClass.ReturnData();
That I am having difficulties with.
As per usual, many thanks in advance folks!