Steps to display images in the grid view control:
It consists the code of Selecting the records from the table and displaying them in the gridviewHandler code:
<%@ WebHandler Language="C#" Class="Handler" %>
using System;using System.Web;using System.Configuration;using System.Data.SqlClient;
public class Handler : IHttpHandler { public void ProcessRequest (HttpContext context) { SqlConnection con = new SqlConnection(); con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
// Create SQL Command
SqlCommand cmd = new SqlCommand(); cmd.CommandText = "Select ImageName,Image from Images where ID =@ID"; cmd.CommandType = System.Data.CommandType.Text; cmd.Connection = con;
SqlParameter ImageID = new SqlParameter("@ID", System.Data.SqlDbType.Int); ImageID.Value = context.Request.QueryString["ID"]; cmd.Parameters.Add(ImageID); con.Open(); SqlDataReader dReader = cmd.ExecuteReader(); dReader.Read(); context.Response.BinaryWrite((byte[])dReader["Image"]); dReader.Close(); con.Close(); } public bool IsReusable { get { return false; } }
}
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: