Results 1 to 8 of 8

Thread: Display picture in datagrid

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602

    Display picture in datagrid

    This is a really simple thing, but I can't get it right I have a field in the dataset that is 0 or 1, and I want to display a small gif pic in the datagrid instead of the 1 or 0. How can this be done? I am using boundcolumns in the datagrid...

    kind regards
    Henrik

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Bump

    kind regards
    Henrik

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    You don't use a bound column, you use a template column. Then you will add a image control to the template. Then add the logic in your code to set the image source appropriately.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Okay... I will try that! Thanks!

    kind regards
    Henrik

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    Hmm this was not as easy as thought....

    I did a drag/drop of an asp image control to the itemtemplate.
    Then I need to get some logic for the "imageurl" property... The question is how do I write that code so it is being accepted? I have done this 1000 times in asp, but it doesn't seem to work the same way in asp.net

    I write like this

    imageurl="<%# if Container.DataItem("status") = 1 then Response.Write("../Red.gif") else Response.Write("../green.gif") endif %>"



    It doesn't feel like the right way to do this, because I am using a data binding expression "#"... but I need to use the "Container.DataItem" to get the value for each row...

    I also tried the DataBinder.Eval()... but still I get "expression expected"...



    kind regards
    HEnrik
    ps I know my code looks like mumbo-jumbo ... but I am still stuck in the old asp way of writing asp pages... ds
    Last edited by MrNorth; Jan 19th, 2004 at 12:51 PM.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    bump

  7. #7
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    imageurl="<%# if Container.DataItem("status") = 1 then Response.Write("../Red.gif") else Response.Write("../green.gif") endif %>"
    You are almost there. Create a PUBLIC function in your code that returns a string.

    Public Function GetImage(image as boolean) as string
    ...Do comparison here, return the image path
    End Function


    Then it will be something like this to call it:
    imageurl="<%# GetImage(Container.DataItem("status")) %>"

    This is very helpful during other situations where you need to process code based on a value.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    May 2002
    Posts
    1,602
    working like a charm, thanks... it was really easy, when one think about the logic in it... I have to lay off those response.writes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width