Click here to Skip to main content
12,953,700 members (51,830 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hii i m new in asp and trying to upload image in folder(in website)and show in gridview but image is going in folder and path also going in database bt image is not showing image
How can i get image in gridview..plzzz any body help me...Thnxx
I m showing code here...

.aspx page code is..
 <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head id="Head1" runat="server">
    <title>Save Images In Folder and Display Images in Gridview from folder</title>
 <style type="text/css">
    <form id="form1" runat="server">
    <asp:FileUpload ID="fileuploadimages" runat="server" />
    <br />
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />
    <asp:GridView runat="server" ID="gvImages" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource1" CssClass="Gridview" 
            HeaderStyle-BackColor="#61A6F8" >
    <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" 
            ReadOnly="True" SortExpression="Id" />
    <asp:BoundField DataField="ImageName" HeaderText="ImageName" 
            SortExpression="ImageName" />
        <asp:BoundField DataField="ImagePath" HeaderText="ImagePath" 
            SortExpression="ImagePath" />
<HeaderStyle BackColor="#61A6F8"></HeaderStyle>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ImageConnectionString %>" 
            SelectCommand="SELECT * FROM [ImagesPath]"></asp:SqlDataSource>

.cs code is
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
    protected void btnSubmit_Click(object sender, EventArgs e)
        //Get Filename from fileupload control
        string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
        //Save images into Images folder
        fileuploadimages.SaveAs(Server.MapPath("Images/" + filename));
        //Getting dbconnection from web.config connectionstring
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ImageConnectionString"].ToString());
        //Open the database connection
        //Query to insert images path and name into database
        SqlCommand cmd = new SqlCommand("Insert into ImagesPath(ImageName,ImagePath) values(@ImageName,@ImagePath)", con);
        //Passing parameters to query
        cmd.Parameters.AddWithValue("@ImageName", filename);
        cmd.Parameters.AddWithValue("@ImagePath", "Images/" + filename);
        //Close dbconnection
Posted 9-Jan-14 1:07am
Updated 9-Jan-14 1:08am
KARTHIK Bangalore 9-Jan-14 7:42am
there is no code to display images...
er.rakesh 13-Jan-14 7:19am
plz show the content of your database i.e.
SELECT * FROM [ImagesPath]

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


In your code there is not any display image code.
You need to try Display image gallery in ASP.NET GridView Control[^].
You also can try this for step by step tutorial:
GridView Examples for ASP.NET 2.0: Displaying Images in a GridView Column[^]

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
ppolymorphe 2,020
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 13 Jan 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100