1 Replies - 3603 Views - Last Post: 21 June 2013 - 02:34 PM Rate Topic: -----

#1 javedparamount  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 28-July 09

Display image in gridview from folder in my website

Posted 17 June 2013 - 04:58 PM

Currently I am uploading images to a folder "Images" in my website using "file upload" control, and I store image path in a column in my database.

I can display all data from database using gridview but i don't know how to display image on the basis of image path.
Following is my vb.net coding to upload image to folder and other information to database. Please tell me how to get image from folder to display. Coding???

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.IO
Imports System.Collections.Generic


Public Class Registration1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnsave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnsave.Click
        
        Dim filename As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
        FileUpload1.SaveAs(Server.MapPath("~/images/" + filename))

        Dim ConnStr As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=D:\NewTop\NTF\newtop\newtop\App_Data\student.mdf;Integrated Security=True;User Instance=True"


        Dim QurStr As String = "insert into tbl values('" + txtname.Text + "','" + txtclass.Text + "',@fileupload1)"
        Using sqlconn As New SqlConnection(ConnStr)
            Dim sqlcomd As SqlCommand = sqlconn.CreateCommand()
            sqlcomd.CommandText = QurStr
            sqlconn.Open()
            sqlcomd.Parameters.AddWithValue("@fileupload1", "~/images/" + filename)
            sqlcomd.ExecuteNonQuery()
        End Using

       
    End Sub
End Class




Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Display image in gridview from folder in my website

#2 jace75  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 31
  • Joined: 11-June 13

Re: Display image in gridview from folder in my website

Posted 21 June 2013 - 02:34 PM

All data files need to be wrapped within an object designed to handle them. In asp, you have the Image class, which is called from aspx view as...

<asp:Image id="myID" runat="server" ImageUrl="the-path-to-your-file" />.



you could also display them using a simple html <img> tag...

<img src="the-path-to-your-file" />



Either way, you should have no problem displaying your images wherever and however you need, as both types of object support css and javascript.

Happy coding B)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1