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. ASP.NET DataGrid Issue

ASP.NET DataGrid Issue

Scheduled Pinned Locked Moved ASP.NET
csharphtmlasp-netdatabasehelp
8 Posts 3 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.
  • B Offline
    B Offline
    braber
    wrote on last edited by
    #1

    Hello all, I am using the dataGrid control to display inventory form a database. The very last field in the database has just an HTML text string somehting like "no Photo", when the dataGrid hits this field everything works great. I am trying to fine tune it a little, so when an image of the product does not exist, who do I get an alternate image to show in the dataGrid? Heeler

    J V 2 Replies Last reply
    0
    • B braber

      Hello all, I am using the dataGrid control to display inventory form a database. The very last field in the database has just an HTML text string somehting like "no Photo", when the dataGrid hits this field everything works great. I am trying to fine tune it a little, so when an image of the product does not exist, who do I get an alternate image to show in the dataGrid? Heeler

      J Offline
      J Offline
      Jon G
      wrote on last edited by
      #2

      Does your datagrid have a Image Server control to hold the image? If so, you can do somethign like this:

      If System.IO.File.Exists("PATHTOIMAGE") = False Then
      CType(MyDataGrid.Items(ROW).FindControl("IMAGEHOLDERCONTROLNAME"), System.Web.UI.webControls.Image).ImageUrl = "PATHTOBLANKIMAGE"
      Else
      CType(MyDataGrid.Items(ROW).FindControl("IMAGEHOLDERCONTROLNAME"), System.Web.UI.webControls.Image).ImageUrl = "PATHTOIMAGE"
      End If

      MyDataGrid = Your data grid name PATHTOIMAGE = the path to the image taken from the DB ROW = the current row you are working with on the datagrid IMAGEHOLDERCONTROLNAME = the name of the control to hold the image inside the dg PATHTOBLANKIMAGE = the path to the blank image to use Jon G www.Gizmocoder.com

      B 1 Reply Last reply
      0
      • J Jon G

        Does your datagrid have a Image Server control to hold the image? If so, you can do somethign like this:

        If System.IO.File.Exists("PATHTOIMAGE") = False Then
        CType(MyDataGrid.Items(ROW).FindControl("IMAGEHOLDERCONTROLNAME"), System.Web.UI.webControls.Image).ImageUrl = "PATHTOBLANKIMAGE"
        Else
        CType(MyDataGrid.Items(ROW).FindControl("IMAGEHOLDERCONTROLNAME"), System.Web.UI.webControls.Image).ImageUrl = "PATHTOIMAGE"
        End If

        MyDataGrid = Your data grid name PATHTOIMAGE = the path to the image taken from the DB ROW = the current row you are working with on the datagrid IMAGEHOLDERCONTROLNAME = the name of the control to hold the image inside the dg PATHTOBLANKIMAGE = the path to the blank image to use Jon G www.Gizmocoder.com

        B Offline
        B Offline
        braber
        wrote on last edited by
        #3

        No, there isnt a server control to house the image, my grid gets bound automatically by the data sources default view. So basically I do not build the datagrid programatically... So when I want to display other forms of the data I just edit the SQL string... Heeler

        J 1 Reply Last reply
        0
        • B braber

          No, there isnt a server control to house the image, my grid gets bound automatically by the data sources default view. So basically I do not build the datagrid programatically... So when I want to display other forms of the data I just edit the SQL string... Heeler

          J Offline
          J Offline
          Jon G
          wrote on last edited by
          #4

          Then the only way I can see you making this possible is by making a specific image reserved for blank entries, and then setting the path in the SQL server DB to that blank image when needed. Jon G www.Gizmocoder.com

          B 1 Reply Last reply
          0
          • J Jon G

            Then the only way I can see you making this possible is by making a specific image reserved for blank entries, and then setting the path in the SQL server DB to that blank image when needed. Jon G www.Gizmocoder.com

            B Offline
            B Offline
            braber
            wrote on last edited by
            #5

            That would be ideal, any ideas on how to do that? Really I have a stored proceedure that creates the HTML string for the picture based on the item # of the product and adds that string to the database field for all records. Thanks Heeler

            1 Reply Last reply
            0
            • B braber

              Hello all, I am using the dataGrid control to display inventory form a database. The very last field in the database has just an HTML text string somehting like "no Photo", when the dataGrid hits this field everything works great. I am trying to fine tune it a little, so when an image of the product does not exist, who do I get an alternate image to show in the dataGrid? Heeler

              V Offline
              V Offline
              Valeria Bogdevich
              wrote on last edited by
              #6

              Maybe this could help you: Code-behind: ... C#: public bool IsImageAvailable(String photo) { String path = "name_of_file_here"; return File.Exists(Server.MapPath(path)); }

              B 1 Reply Last reply
              0
              • V Valeria Bogdevich

                Maybe this could help you: Code-behind: ... C#: public bool IsImageAvailable(String photo) { String path = "name_of_file_here"; return File.Exists(Server.MapPath(path)); }

                B Offline
                B Offline
                braber
                wrote on last edited by
                #7

                That looks like it might work, i'll give it a shot.... thanks Heeler

                B 1 Reply Last reply
                0
                • B braber

                  That looks like it might work, i'll give it a shot.... thanks Heeler

                  B Offline
                  B Offline
                  braber
                  wrote on last edited by
                  #8

                  Thanks WiB, I used your C# method and modified the way the database inserts that field. Thank you for your help... The ASP side wouldn't work because of the way the Grid was bound. But I used part of your code so thank you very much. Actually thanks to everyone that replied... :) Heeler

                  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