Hi,
How to display image in GridView in asp.net ?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Aug 12, 2011, 3:31 PM
Here is your desired code and run the attachments.
Default.aspx code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
Default.aspx.vb code
Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Dim com As SqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
Dim str As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
bindgrid()
End Sub
Sub bindgrid()
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()
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
GridView1.PageIndex = e.NewPageIndex
bindgrid()
End Sub
End Class
Thanks
If this post helps you mark it as answer
Mayur DighePosted Aug 12, 2011, 2:23 AM
Image in Gridview control can be displayed using 3 format:
1. MemoryStream
2. Binary Data
3. Image
Refer below articles.......
http://www.c-sharpcorner.com/UploadFile/jaiganesh.cegon/398/
http://www.c-sharpcorner.com/Blogs/3453/
http://www.c-sharpcorner.com/Blogs/3456/
http://www.c-sharpcorner.com/Blogs/2183/add-image-on-datagridview-cell-header.aspx
if you like anwser mark it as Accepted Answer