473,382 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How do you alternate images in a data bound column of a data grid control?

I have a data grid control taht contains a data bound coulmn called "Type".
Depending on the value of "Type" I want to display a corresponding image in
the rendered table cell. So, if the value of type is 1, I want to show
image1.gif. If the value is 2, I want to show image2.gif. Is there an easy
way to do this?

TIA//
Nov 18 '05 #1
9 1965
If SQL Server, you can do it in your statement:

, 'image'+imageType+'.gif' As ImageName

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"C Newby" <ca*@democracydata.com> wrote in message
news:u8**************@tk2msftngp13.phx.gbl...
I have a data grid control taht contains a data bound coulmn called "Type". Depending on the value of "Type" I want to display a corresponding image in the rendered table cell. So, if the value of type is 1, I want to show
image1.gif. If the value is 2, I want to show image2.gif. Is there an easy
way to do this?

TIA//

Nov 18 '05 #2
Right, but i was hoping for something i could determine at run time. Any
thoughts on that? Thanks for your reply.

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:eU**************@TK2MSFTNGP11.phx.gbl...
If SQL Server, you can do it in your statement:

, 'image'+imageType+'.gif' As ImageName

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************** ********************
Think Outside the Box!
************************************************** ********************
"C Newby" <ca*@democracydata.com> wrote in message
news:u8**************@tk2msftngp13.phx.gbl...
I have a data grid control taht contains a data bound coulmn called

"Type".
Depending on the value of "Type" I want to display a corresponding image

in
the rendered table cell. So, if the value of type is 1, I want to show
image1.gif. If the value is 2, I want to show image2.gif. Is there an easy way to do this?

TIA//


Nov 18 '05 #3
You can also write a function in your databinding expression for the image cell, e.g. imageurl (or src)=<%# GetMyImage(parms) %>, where GetMyImage is an accessible method (e.g. page.getmyimage), and parms is whatever you want to pass to get the image (the value of Type in this case)

----- C Newby wrote: ----

Right, but i was hoping for something i could determine at run time. An
thoughts on that? Thanks for your reply

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote i
message news:eU**************@TK2MSFTNGP11.phx.gbl..
If SQL Server, you can do it in your statement
, 'image'+imageType+'.gif' As ImageNam
--

Gregory A. Beame
MVP; MCP: +I, SE, SD, DB
************************************************** *******************

Think Outside the Box
************************************************** *******************
"C Newby" <ca*@democracydata.com> wrote in messag
news:u8**************@tk2msftngp13.phx.gbl..
I have a data grid control taht contains a data bound coulmn calle

"Type"
Depending on the value of "Type" I want to display a corresponding imag

i
the rendered table cell. So, if the value of type is 1, I want to sho
image1.gif. If the value is 2, I want to show image2.gif. Is there a eas way to do this
TIA/
>>

Nov 18 '05 #4
Ah gotcha...thanks Bill, that's what i was looking for.

"Bill Borg" <an*******@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
You can also write a function in your databinding expression for the image cell, e.g. imageurl (or src)=<%# GetMyImage(parms) %>, where GetMyImage is
an accessible method (e.g. page.getmyimage), and parms is whatever you want
to pass to get the image (the value of Type in this case).
----- C Newby wrote: -----

Right, but i was hoping for something i could determine at run time. Any thoughts on that? Thanks for your reply.

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in message news:eU**************@TK2MSFTNGP11.phx.gbl...
> If SQL Server, you can do it in your statement:
>> , 'image'+imageType+'.gif' As ImageName
>> -- > Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>> ************************************************** ********************
> Think Outside the Box!
> ************************************************** ********************
> "C Newby" <ca*@democracydata.com> wrote in message
> news:u8**************@tk2msftngp13.phx.gbl...
>> I have a data grid control taht contains a data bound coulmn
called > "Type".
>> Depending on the value of "Type" I want to display a corresponding
image > in
>> the rendered table cell. So, if the value of type is 1, I want to

show >> image1.gif. If the value is 2, I want to show image2.gif. Is there

an easy >> way to do this?
>>>> TIA//
>>>>>>

Nov 18 '05 #5
Actually, that's not working for me. When the page renders, the table cell
just contains the expression. For example, i have something like:
<asp:BoundColumn DataField="Something" HeaderText="Something"
DataFormatString="<%=getSomething({0})%>"></asp:BoundColumn>

which renders:
<td><%=getSomething( SomeType )%></td>

But I do have a protected member method of the code behind class called
getSomething( someType Type ){ return "something"; }

Any thoughts?

thanks//
"Bill Borg" <an*******@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
You can also write a function in your databinding expression for the image cell, e.g. imageurl (or src)=<%# GetMyImage(parms) %>, where GetMyImage is
an accessible method (e.g. page.getmyimage), and parms is whatever you want
to pass to get the image (the value of Type in this case).
----- C Newby wrote: -----

Right, but i was hoping for something i could determine at run time. Any thoughts on that? Thanks for your reply.

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in message news:eU**************@TK2MSFTNGP11.phx.gbl...
> If SQL Server, you can do it in your statement:
>> , 'image'+imageType+'.gif' As ImageName
>> -- > Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>> ************************************************** ********************
> Think Outside the Box!
> ************************************************** ********************
> "C Newby" <ca*@democracydata.com> wrote in message
> news:u8**************@tk2msftngp13.phx.gbl...
>> I have a data grid control taht contains a data bound coulmn
called > "Type".
>> Depending on the value of "Type" I want to display a corresponding
image > in
>> the rendered table cell. So, if the value of type is 1, I want to

show >> image1.gif. If the value is 2, I want to show image2.gif. Is there

an easy >> way to do this?
>>>> TIA//
>>>>>>

Nov 18 '05 #6
You need to use a template column, not a bound column, which you can create in the property builder in the idea, or straight in the html. Bound column is good for showing something that resolves to text (and the format string can format it for you), but you need a picture in this case. Try something like this, where GetMyPicture is your function that returns the filename of the image you want to show. In my case, I'm passing container.dataitem("cs_key"), which will resolve to the cs_key field in the datasource. In your case, for cs_key you'll use the column name of your type field

<asp:TemplateColumn HeaderText="My Picture Column"><itemtemplate><img src='<%# GetMyPicture(container.dataitem("cs_key")) %>'/> (don't forget the '#'
</itemtemplate></asp:TemplateColumn

Regarding the protected function, that should be fine, but if at run-time it can't find it you'll get a semi-friendly message, something to the effect of "...GetMyPicture is not declared...

hth

Bil

----- C Newby wrote: ----

Actually, that's not working for me. When the page renders, the table cel
just contains the expression. For example, i have something like
<asp:BoundColumn DataField="Something" HeaderText="Something
DataFormatString="<%=getSomething({0})%>"></asp:BoundColumn

which renders
<td><%=getSomething( SomeType )%></td

But I do have a protected member method of the code behind class calle
getSomething( someType Type ){ return "something";

Any thoughts

thanks/
"Bill Borg" <an*******@discussions.microsoft.com> wrote in messag
news:C6**********************************@microsof t.com..
You can also write a function in your databinding expression for the imag cell, e.g. imageurl (or src)=<%# GetMyImage(parms) %>, where GetMyImage i
an accessible method (e.g. page.getmyimage), and parms is whatever you wan
to pass to get the image (the value of Type in this case)
----- C Newby wrote: ----
Right, but i was hoping for something i could determine at run time An thoughts on that? Thanks for your reply "Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM wrote i
message news:eU**************@TK2MSFTNGP11.phx.gbl..
If SQL Server, you can do it in your statement
, 'image'+imageType+'.gif' As ImageNam
-- Gregory A. Beame
MVP; MCP: +I, SE, SD, DB
************************************************** *******************
Think Outside the Box

************************************************** *******************
"C Newby" <ca*@democracydata.com> wrote in messag
news:u8**************@tk2msftngp13.phx.gbl..
I have a data grid control taht contains a data bound coulm
calle "Type"
Depending on the value of "Type" I want to display a correspondin
imag i
the rendered table cell. So, if the value of type is 1, I want t

sho image1.gif. If the value is 2, I want to show image2.gif. Is ther

a eas way to do this
> TIA/
>>>

Nov 18 '05 #7
You need to use a template column, not a bound column, which you can create in the property builder in the idea, or straight in the html. Bound column is good for showing something that resolves to text (and the format string can format it for you), but you need a picture in this case. Try something like this, where GetMyPicture is your function that returns the filename of the image you want to show. In my case, I'm passing container.dataitem("cs_key"), which will resolve to the cs_key field in the datasource. In your case, for cs_key you'll use the column name of your type field

<asp:TemplateColumn HeaderText="My Picture Column"><itemtemplate><img src='<%# GetMyPicture(container.dataitem("cs_key")) %>'/> (don't forget the '#'
</itemtemplate></asp:TemplateColumn

Regarding the protected function, that should be fine, but if at run-time it can't find it you'll get a semi-friendly message, something to the effect of "...GetMyPicture is not declared...

hth

Bil

----- C Newby wrote: ----

Actually, that's not working for me. When the page renders, the table cel
just contains the expression. For example, i have something like
<asp:BoundColumn DataField="Something" HeaderText="Something
DataFormatString="<%=getSomething({0})%>"></asp:BoundColumn

which renders
<td><%=getSomething( SomeType )%></td

But I do have a protected member method of the code behind class calle
getSomething( someType Type ){ return "something";

Any thoughts

thanks/
"Bill Borg" <an*******@discussions.microsoft.com> wrote in messag
news:C6**********************************@microsof t.com..
You can also write a function in your databinding expression for the imag cell, e.g. imageurl (or src)=<%# GetMyImage(parms) %>, where GetMyImage i
an accessible method (e.g. page.getmyimage), and parms is whatever you wan
to pass to get the image (the value of Type in this case)
----- C Newby wrote: ----
Right, but i was hoping for something i could determine at run time An thoughts on that? Thanks for your reply "Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM wrote i
message news:eU**************@TK2MSFTNGP11.phx.gbl..
If SQL Server, you can do it in your statement
, 'image'+imageType+'.gif' As ImageNam
-- Gregory A. Beame
MVP; MCP: +I, SE, SD, DB
************************************************** *******************
Think Outside the Box

************************************************** *******************
"C Newby" <ca*@democracydata.com> wrote in messag
news:u8**************@tk2msftngp13.phx.gbl..
I have a data grid control taht contains a data bound coulm
calle "Type"
Depending on the value of "Type" I want to display a correspondin
imag i
the rendered table cell. So, if the value of type is 1, I want t

sho image1.gif. If the value is 2, I want to show image2.gif. Is ther

a eas way to do this
> TIA/
>>>

Nov 18 '05 #8
Thanks again Bill,

I was able to get it working this time. One thing though,
"container.dataitem("myField")" didn't work for me, I ended up using:
"DataBinder.Eval(Container, "DataItem.myField")". Any thoughts on that?

Hey again, I really apreciate the help//

"Bill Borg" <an*******@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.com...
You need to use a template column, not a bound column, which you can create in the property builder in the idea, or straight in the html. Bound
column is good for showing something that resolves to text (and the format
string can format it for you), but you need a picture in this case. Try
something like this, where GetMyPicture is your function that returns the
filename of the image you want to show. In my case, I'm passing
container.dataitem("cs_key"), which will resolve to the cs_key field in the
datasource. In your case, for cs_key you'll use the column name of your
type field.
<asp:TemplateColumn HeaderText="My Picture Column"><itemtemplate><img src='<%# GetMyPicture(container.dataitem("cs_key")) %>'/> (don't forget the
'#') </itemtemplate></asp:TemplateColumn>
Regarding the protected function, that should be fine, but if at run-time it can't find it you'll get a semi-friendly message, something to the effect
of "...GetMyPicture is not declared..."
hth,

Bill

----- C Newby wrote: -----

Actually, that's not working for me. When the page renders, the table cell just contains the expression. For example, i have something like:
<asp:BoundColumn DataField="Something" HeaderText="Something"
DataFormatString="<%=getSomething({0})%>"></asp:BoundColumn>

which renders:
<td><%=getSomething( SomeType )%></td>

But I do have a protected member method of the code behind class called getSomething( someType Type ){ return "something"; }

Any thoughts?

thanks//
"Bill Borg" <an*******@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
> You can also write a function in your databinding expression for the image
cell, e.g. imageurl (or src)=<%# GetMyImage(parms) %>, where GetMyImage is an accessible method (e.g. page.getmyimage), and parms is whatever you want to pass to get the image (the value of Type in this case). >> ----- C Newby wrote: -----
>> Right, but i was hoping for something i could determine at run time.
Any
> thoughts on that? Thanks for your reply.
>>>> "Cowboy (Gregory A. Beamer)"
<No************@comcast.netNoSpamM>
wrote in
> message news:eU**************@TK2MSFTNGP11.phx.gbl...
>> If SQL Server, you can do it in your statement:
>>> , 'image'+imageType+'.gif' As ImageName
>>> --
>> Gregory A. Beamer
>> MVP; MCP: +I, SE, SD, DBA
>>>

************************************************** ******************** >> Think Outside the Box!
>>

************************************************** ********************
>> "C Newby" <ca*@democracydata.com> wrote in message
>> news:u8**************@tk2msftngp13.phx.gbl...
>>> I have a data grid control taht contains a data bound coulmn called >> "Type".
>>> Depending on the value of "Type" I want to display a
corresponding image >> in
>>> the rendered table cell. So, if the value of type is 1, I want to show >>> image1.gif. If the value is 2, I want to show image2.gif. Is
there an
> easy
>>> way to do this?
>>>>> TIA//
>>>>>>>

Nov 18 '05 #9
Thanks again Bill,

I was able to get it working this time. One thing though,
"container.dataitem("myField")" didn't work for me, I ended up using:
"DataBinder.Eval(Container, "DataItem.myField")". Any thoughts on that?

Hey again, I really apreciate the help//

"Bill Borg" <an*******@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.com...
You need to use a template column, not a bound column, which you can create in the property builder in the idea, or straight in the html. Bound
column is good for showing something that resolves to text (and the format
string can format it for you), but you need a picture in this case. Try
something like this, where GetMyPicture is your function that returns the
filename of the image you want to show. In my case, I'm passing
container.dataitem("cs_key"), which will resolve to the cs_key field in the
datasource. In your case, for cs_key you'll use the column name of your
type field.
<asp:TemplateColumn HeaderText="My Picture Column"><itemtemplate><img src='<%# GetMyPicture(container.dataitem("cs_key")) %>'/> (don't forget the
'#') </itemtemplate></asp:TemplateColumn>
Regarding the protected function, that should be fine, but if at run-time it can't find it you'll get a semi-friendly message, something to the effect
of "...GetMyPicture is not declared..."
hth,

Bill

----- C Newby wrote: -----

Actually, that's not working for me. When the page renders, the table cell just contains the expression. For example, i have something like:
<asp:BoundColumn DataField="Something" HeaderText="Something"
DataFormatString="<%=getSomething({0})%>"></asp:BoundColumn>

which renders:
<td><%=getSomething( SomeType )%></td>

But I do have a protected member method of the code behind class called getSomething( someType Type ){ return "something"; }

Any thoughts?

thanks//
"Bill Borg" <an*******@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
> You can also write a function in your databinding expression for the image
cell, e.g. imageurl (or src)=<%# GetMyImage(parms) %>, where GetMyImage is an accessible method (e.g. page.getmyimage), and parms is whatever you want to pass to get the image (the value of Type in this case). >> ----- C Newby wrote: -----
>> Right, but i was hoping for something i could determine at run time.
Any
> thoughts on that? Thanks for your reply.
>>>> "Cowboy (Gregory A. Beamer)"
<No************@comcast.netNoSpamM>
wrote in
> message news:eU**************@TK2MSFTNGP11.phx.gbl...
>> If SQL Server, you can do it in your statement:
>>> , 'image'+imageType+'.gif' As ImageName
>>> --
>> Gregory A. Beamer
>> MVP; MCP: +I, SE, SD, DBA
>>>

************************************************** ******************** >> Think Outside the Box!
>>

************************************************** ********************
>> "C Newby" <ca*@democracydata.com> wrote in message
>> news:u8**************@tk2msftngp13.phx.gbl...
>>> I have a data grid control taht contains a data bound coulmn called >> "Type".
>>> Depending on the value of "Type" I want to display a
corresponding image >> in
>>> the rendered table cell. So, if the value of type is 1, I want to show >>> image1.gif. If the value is 2, I want to show image2.gif. Is
there an
> easy
>>> way to do this?
>>>>> TIA//
>>>>>>>

Nov 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: moondaddy | last post by:
Happy Holidays All! I want to load a datagrid with images and text (Image, text, image, text, etc...). The data for this datagrid will be coming from sql server and the images are stored as files...
7
by: C Newby | last post by:
I have a data grid control taht contains a data bound coulmn called "Type". Depending on the value of "Type" I want to display a corresponding image in the rendered table cell. So, if the value of...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
3
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a generic list of data list <typelistcategory; listcategory = new list <type>; I also have a dropdown box that I have put into a template column of a gridview. I was able to populate...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.