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. General Programming
  3. C#
  4. Showing a "Image" in a Datagrid

Showing a "Image" in a Datagrid

Scheduled Pinned Locked Moved C#
data-structuresquestiondiscussion
3 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.
  • N Offline
    N Offline
    Nooie
    wrote on last edited by
    #1

    Hi all, I am trying to show a "Image" in a DataGrid. I have a new class I created that has 3 properties that are string and one that is of type image. I create an Array of this class, and make the DataGrid source the Array. But the image column comes up as a red cross in a white background, i.e. its not an image. Can anyone give me some idea of best practice to show an image in a DataGrid please? Regards Tony

    K 1 Reply Last reply
    0
    • N Nooie

      Hi all, I am trying to show a "Image" in a DataGrid. I have a new class I created that has 3 properties that are string and one that is of type image. I create an Array of this class, and make the DataGrid source the Array. But the image column comes up as a red cross in a white background, i.e. its not an image. Can anyone give me some idea of best practice to show an image in a DataGrid please? Regards Tony

      K Offline
      K Offline
      Keshav V Kamat 0
      wrote on last edited by
      #2

      Hi Tony, hope the following code works.

      private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
      {
      System.Web.UI.WebControls.Image anImagine ;
      if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item )
      {
      anImagine = ((System.Web.UI.WebControls.Image)e.Item.Cells[1].Controls[1]); anImagine.ImageUrl="icons/" + e.Item.Cells[0].Text.ToString() + ".gif";
      }
      }

      Keshav Kamat :) India

      N 1 Reply Last reply
      0
      • K Keshav V Kamat 0

        Hi Tony, hope the following code works.

        private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
        System.Web.UI.WebControls.Image anImagine ;
        if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item )
        {
        anImagine = ((System.Web.UI.WebControls.Image)e.Item.Cells[1].Controls[1]); anImagine.ImageUrl="icons/" + e.Item.Cells[0].Text.ToString() + ".gif";
        }
        }

        Keshav Kamat :) India

        N Offline
        N Offline
        Nooie
        wrote on last edited by
        #3

        Hi Keshav, Many thanks for the reply I will give it a try. Many thanks again Tony

        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