Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a grid view. In gridview I want to show image from database. For that I took a httphandler.ashx code file. What I did not understand is how or where to add it?

<%@ WebHandler Language="C#" Class="Handler" %>
and the code of .ashx file is:
C#
using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using TestWebMsgApp;
using System.Web.UI.WebControls;
using System.Web.SessionState;

namespace SchoolMgtSys.Hostal.Forms
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class myhandler : IHttpHandler, IReadOnlySessionState
    {
        //Global object and vriables Declertion
        class_section cs = new class_section();
        prophostalfine obj_prop = new prophostalfine();
        hostalfineclass obj = new hostalfineclass();
        intstudent_hostl prp_hostal = new intstudent_hostl();
        hostalclass obj_hostl = new hostalclass();
        public ClsTimeTable objtime = new ClsTimeTable();
        clsTimetableprp objtimeprp = new clsTimetableprp();

       // public bool IsReusable { get { return true; } }
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                string strId = context.Request.QueryString["st_id"];
                prp_hostal.stid = Convert.ToInt32(strId);
               context.Response.BinaryWrite(obj_hostl.get_read(prp_hostal));
               context.Response.End();
            }
            catch (Exception ew)
            {
                WebMsgBox.Show(ew.Message);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
Posted
Updated 20-Aug-10 19:27pm
v2
Comments
Sandeep Mewara 21-Aug-10 1:27am    
Formatted for better readability.

1. You should never do it without understanding. Getting a file from somewhere and putting it by hit-n-try or asking others would not help you in a long run.

2. Learn about HTTPHandlers first. What are they and how they can be used.

I could have provided you a link of sample article showing images from database in a grid. But for now, you will not learn anything if I do so. Try first, know how things work and then post if you have specific issue.
 
Share this answer
 
Comments
sharmarun 21-Aug-10 1:35am    
Thanxz MAn For ur link
Here is the good post of Abhijit.

Displaying Image in Gridview from Database[^]

:thumbsup:
 
Share this answer
 
Comments
sharmarun 21-Aug-10 4:51am    
Thanxz

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900