Click to See Complete Forum and Search --> : Display picture in datagrid
MrNorth
Jan 16th, 2004, 08:37 AM
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
MrNorth
Jan 17th, 2004, 05:35 AM
Bump :confused: :eek:
kind regards
Henrik
hellswraith
Jan 17th, 2004, 10:05 AM
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.
MrNorth
Jan 17th, 2004, 11:26 AM
Okay... I will try that! Thanks!
kind regards
Henrik
MrNorth
Jan 19th, 2004, 02:06 AM
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 ...:blush: but I am still stuck in the old asp way of writing asp pages... :( ds
MrNorth
Jan 20th, 2004, 12:58 AM
bump :blush:
hellswraith
Jan 20th, 2004, 02:14 AM
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.
MrNorth
Jan 20th, 2004, 02:54 AM
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 :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.