How to show image in gridview c#
how to show image in c# gridview
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Oct 24, 2012, 10:07 PM EDT
create a table student
Create table student (sid varchar(50),sname varchar(50),saddress varchar(50), smarks int,pic nvarchar (50))
Store the picture in the program folder and save there name in pic column of the table with there extension like (.gif,.jpg,.bmp).
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Show_image_in_gridview._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
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;
using System.Data.SqlClient;
namespace Show_image_in_gridview
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
void bindgrid()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "SELECT * FROM student";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "student");
GridView1.DataSource = ds;
GridView1.DataMember = "student";
GridView1.DataBind();
con.Close();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bindgrid();
}
}
}
Thanks
If this post helps you mark it as answer
Vishnujeet KumarRank #1,019 · 1.9K reputationPosted Nov 2, 2012, 1:40 AM EDT
http://www.codeproject.com/Articles/20782/Displaying-Images-from-a-Database-in-a-GridView