Click here to Skip to main content
15,891,136 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionwhich is the best practice to generate report in pdf format using ASP.NET MVC3? Pin
manoj.jsm8-May-13 0:20
manoj.jsm8-May-13 0:20 
Questionexpansion of axd in trace.axd Pin
Member 87018137-May-13 21:28
Member 87018137-May-13 21:28 
QuestionRe: expansion of axd in trace.axd Pin
Sandeep Mewara7-May-13 22:41
mveSandeep Mewara7-May-13 22:41 
AnswerRe: expansion of axd in trace.axd Pin
Member 870181310-May-13 7:46
Member 870181310-May-13 7:46 
QuestionHow to Display image with Grideview Pin
langpolen7-May-13 20:55
langpolen7-May-13 20:55 
AnswerRe: How to Display image with Grideview Pin
Sandeep Mewara7-May-13 22:42
mveSandeep Mewara7-May-13 22:42 
AnswerRe: How to Display image with Grideview Pin
AANIL DHAKAD8-May-13 2:56
AANIL DHAKAD8-May-13 2:56 
AnswerRe: How to Display image with Grideview Pin
Bikash Prakash Dash8-May-13 4:23
Bikash Prakash Dash8-May-13 4:23 
create a generic handler file e.g.-> showpic.ashx
with code
C#
<%@ WebHandler Language="C#" Class="showpic" %>

 

using System;

using System.Web;

using System.Data.SqlClient;

using System.Data;

using System.IO;

using System.Collections.Specialized;

 

public class showpic: IHttpHandler {

 

    public string GetConnectionString()

    {

        //sets the connection string from your web config file "ConnString" is the name of your Connection String

        return System.Configuration.ConfigurationManager.ConnectionStrings["b4mConnectionString"].ConnectionString;

    }

    public void ProcessRequest(HttpContext context)

    {

        string id = context.Request.QueryString["id"]; //get the querystring value that was pass on the ImageURL (see GridView MarkUp in Page1.aspx)
        string img = context.Request.QueryString["img"];
        if (id != null)

        {


            try
            {
                MemoryStream memoryStream = new MemoryStream();

                SqlConnection connection = new SqlConnection(GetConnectionString());

                string sql = "SELECT " + img + " FROM useraccount WHERE userid= @id";



                SqlCommand cmd = new SqlCommand(sql, connection);


                cmd.Parameters.AddWithValue("@id", id);

                connection.Open();



                SqlDataReader reader = cmd.ExecuteReader();

                reader.Read();


                byte[] file = (byte[])reader[0];



                reader.Close();

                connection.Close();

                memoryStream.Write(file, 0, file.Length);

                context.Response.Buffer = true;

                context.Response.BinaryWrite(file);

                memoryStream.Dispose();
            }
            catch
            { 
            
            }
 

        }

    }

 

    public bool IsReusable {

        get {

            return false;

        }

    }

}

change the database & query parameters

within the gridview create a templated field with Image control
In Image Url property set the following code
HTML
'<%# "generics/showpic.ashx?id="+Eval("userid")+"&img=picture" %>'


e.g-> <asp:Image ID="Image1" runat="server" Height="60px"
ImageUrl='<%# "generics/showpic.ashx?id="+Eval("userid")+"&img=picture" %>'
Width="60px" />
change as per your database configuration.

now you will be able to show picture in gridview
Regards
Bikash

Questionbest way to move website from development to production Pin
Jassim Rahma7-May-13 10:30
Jassim Rahma7-May-13 10:30 
AnswerRe: best way to move website from development to production Pin
Sandeep Mewara7-May-13 22:47
mveSandeep Mewara7-May-13 22:47 
QuestionFacebook-Like alert Pin
Jassim Rahma7-May-13 10:29
Jassim Rahma7-May-13 10:29 
AnswerRe: Facebook-Like alert Pin
Sandeep Mewara7-May-13 22:49
mveSandeep Mewara7-May-13 22:49 
QuestionLink My SQL with SQL Server Pin
Member 100349907-May-13 6:35
Member 100349907-May-13 6:35 
AnswerRe: Link My SQL with SQL Server Pin
Sandeep Mewara7-May-13 22:50
mveSandeep Mewara7-May-13 22:50 
Question401 Unauthorized error Pin
vanikanc7-May-13 5:21
vanikanc7-May-13 5:21 
AnswerRe: 401 Unauthorized error Pin
Sandeep Mewara7-May-13 22:55
mveSandeep Mewara7-May-13 22:55 
QuestionWhat do you think about to improve your web applications coding by writing C# instead of JavaScript? Interesting in your opinion. Pin
Wladis7-May-13 4:34
Wladis7-May-13 4:34 
QuestionHow to maintain state of an application Pin
cLeanMy7-May-13 4:09
cLeanMy7-May-13 4:09 
AnswerRe: How to maintain state of an application Pin
Sandeep Mewara7-May-13 22:58
mveSandeep Mewara7-May-13 22:58 
Questionsend sms Pin
hi88807-May-13 3:32
hi88807-May-13 3:32 
AnswerRe: send sms Pin
Sandeep Mewara7-May-13 23:01
mveSandeep Mewara7-May-13 23:01 
Questionwhere to start Pin
Yashwanth. C.b5-May-13 7:48
Yashwanth. C.b5-May-13 7:48 
AnswerRe: where to start Pin
Blikkies5-May-13 21:11
professionalBlikkies5-May-13 21:11 
AnswerRe: where to start Pin
_Amy5-May-13 22:57
professional_Amy5-May-13 22:57 
GeneralRe: where to start Pin
Yashwanth. C.b6-May-13 4:57
Yashwanth. C.b6-May-13 4:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.