Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Help Needed

Help Needed

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelptutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    perms
    wrote on last edited by
    #1

    Hi, How to display images in the datagrid column i am using Asp.net using c#. I am looking code sample or article. Help will be greatly appriciated. Thanks

    M 1 Reply Last reply
    0
    • P perms

      Hi, How to display images in the datagrid column i am using Asp.net using c#. I am looking code sample or article. Help will be greatly appriciated. Thanks

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi there. Try looking up TemplateColumn in the .Net Documentation. You could use a simple <img> tag in a <TemplateColumn> to display images. If the image filename is coming from your data source, then look at the .Net documentation under "data binding expressions". You'll probably end up with something like this (assuming "imgFileName" is the field name for your image files in your datasource):

      asp:TemplateColumn
      <ItemTemplate>
      <img src='<%# DataBinder.Eval(Container.DataItem, "imgFileName") %>' />
      </ItemTemplate>
      </asp:TemplateColumn>

      P 1 Reply Last reply
      0
      • M Mike Ellison

        Hi there. Try looking up TemplateColumn in the .Net Documentation. You could use a simple <img> tag in a <TemplateColumn> to display images. If the image filename is coming from your data source, then look at the .Net documentation under "data binding expressions". You'll probably end up with something like this (assuming "imgFileName" is the field name for your image files in your datasource):

        asp:TemplateColumn
        <ItemTemplate>
        <img src='<%# DataBinder.Eval(Container.DataItem, "imgFileName") %>' />
        </ItemTemplate>
        </asp:TemplateColumn>

        P Offline
        P Offline
        perms
        wrote on last edited by
        #3

        I have used the following code. but still i couldnt diaplay the image, it shows the text System.Byte[] in that column. here is the code try { string Category = Request.QueryString["UserID"]; SqlConnection myConn = new SqlConnection("server=localhost;uid=sa;pwd=;database=BzzzNet"); SqlCommand myCommand = new SqlCommand("perustorproc", myConn); myCommand.CommandType = CommandType.StoredProcedure; myConn.Open(); DG_Persons.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection); DG_Persons.DataBind(); } catch (SqlException ex) { throw new Exception(ex.ToString()); } finally { } --------------- can any one help me to solve this problem. thanks

        M 2 Replies Last reply
        0
        • P perms

          I have used the following code. but still i couldnt diaplay the image, it shows the text System.Byte[] in that column. here is the code try { string Category = Request.QueryString["UserID"]; SqlConnection myConn = new SqlConnection("server=localhost;uid=sa;pwd=;database=BzzzNet"); SqlCommand myCommand = new SqlCommand("perustorproc", myConn); myCommand.CommandType = CommandType.StoredProcedure; myConn.Open(); DG_Persons.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection); DG_Persons.DataBind(); } catch (SqlException ex) { throw new Exception(ex.ToString()); } finally { } --------------- can any one help me to solve this problem. thanks

          M Offline
          M Offline
          Mike Ellison
          wrote on last edited by
          #4

          Hi there. Okay, it looks like you're working with an image stored directly in your database, yes? Remember that when a web server wishes to instruct a browser to display an image, it does so by sending the browser an <img> tag with the src attribute set to the image source. There is no way in standard html for a server to send a Byte[] array to a browser and expect the browser to render it as an image. Typically the src attribute of the <img> tag is set to a file on the server, but it doesn't have to be. You could instead set the src attribute to an .aspx page which is coded to process a request for an image stored in a database, and responds with the image's binary byte stream. Such a tag then would look something like this:

          <img src="myImageRetriever.aspx?imageId=xxx" />

          If you google for stuff like "display image from database asp.net" you will find several exmaples of this sort of thing. Here is one CodeProject Article[^] that discusses the technique. Now, with that being said, displaying images this way is more performance-intensive for your server than say just serving up static image files. You may wish to reconsider storing complete images as binary objects in your database. You may wish instead to store a filename in the database, and render that as the src attribute in your <TemplateColumn>.

          1 Reply Last reply
          0
          • P perms

            I have used the following code. but still i couldnt diaplay the image, it shows the text System.Byte[] in that column. here is the code try { string Category = Request.QueryString["UserID"]; SqlConnection myConn = new SqlConnection("server=localhost;uid=sa;pwd=;database=BzzzNet"); SqlCommand myCommand = new SqlCommand("perustorproc", myConn); myCommand.CommandType = CommandType.StoredProcedure; myConn.Open(); DG_Persons.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection); DG_Persons.DataBind(); } catch (SqlException ex) { throw new Exception(ex.ToString()); } finally { } --------------- can any one help me to solve this problem. thanks

            M Offline
            M Offline
            Mike Ellison
            wrote on last edited by
            #5

            Here's another CodeProject article[^] that shows retrieving images from a database.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups