venmani Kumar

venmani Kumar

  • NA
  • 3
  • 821

Image not Displaying in Gridview asp.net

Nov 7 2014 1:11 PM
when i select the category in dropdownlist it has to bind image in Gridview but the image is not displaying 
My code for aspx is as follows:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDropDownList();
}
}
protected void BindDropDownList()
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * FROM rsa_ProductCategory", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DropSearchCat.DataSource = ds;
DropSearchCat.DataTextField = "Category";
DropSearchCat.DataValueField = "CategoryID";
DropSearchCat.DataBind();
DropSearchCat.Items.Insert(0, new ListItem("--Select--", "0"));
con.Close();
}
protected void DropSearchCat_SelectedIndexChanged1(object sender, EventArgs e)
{
if (DropSearchCat.SelectedIndex > 0)
{
//con.Open();
//SqlCommand cmd = new SqlCommand("select * from rsa_ProductItemTable where Category = '" + DropSearchCat.SelectedValue.ToString() + "'", con);
//SqlDataAdapter Adpt = new SqlDataAdapter(cmd);
//DataTable dt = new DataTable();
//Adpt.Fill(dt);
//GridView1.DataSource = dt;
//GridView1.DataBind();
BindGridData();
}
}
private void BindGridData()
{
con.Open();
SqlCommand command = new SqlCommand("SELECT ProductID,ProductName,ProductDescription,ProductShortDescription,Price, Category,ProductImage from rsa_ProductItemTable where Category = '" + DropSearchCat.SelectedValue.ToString() + "'", con);
SqlDataAdapter daimages = new SqlDataAdapter(command);
DataTable dt = new DataTable();
daimages.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
Handler:
public class Handler : IHttpHandler {
SqlConnection con = new SqlConnection("Data Source=ADMIN-PC\\SQLEXPRESS;Integrated Security=true;Initial Catalog=rsaProducts");
public void ProcessRequest(HttpContext context)
{
string imageid = context.Request.QueryString["ImID"];
con.Open();
SqlCommand command = new SqlCommand("select ProductImage from rsa_ProductItemTable where ProductID=" + imageid, con);
SqlDataReader dr = command.ExecuteReader();
dr.Read();
context.Response.BinaryWrite((Byte[])dr[0]);
con.Close();
context.Response.End();
}

public bool IsReusable {
get {
return false;
}
}
}
But Images is stored in database but problem is not displaying in Gridview
Please Help me with this  

Answers (2)