473,698 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1990
If SQL Server, you can do it in your statement:

, 'image'+imageTy pe+'.gif' As ImageName

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

*************** *************** *************** *************** **********
Think Outside the Box!
*************** *************** *************** *************** **********
"C Newby" <ca*@democracyd ata.com> wrote in message
news:u8******** ******@tk2msftn gp13.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.netNoS pamM> wrote in
message news:eU******** ******@TK2MSFTN GP11.phx.gbl...
If SQL Server, you can do it in your statement:

, 'image'+imageTy pe+'.gif' As ImageName

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

*************** *************** *************** *************** **********
Think Outside the Box!
*************** *************** *************** *************** **********
"C Newby" <ca*@democracyd ata.com> wrote in message
news:u8******** ******@tk2msftn gp13.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(parm s) %>, 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.netNoS pamM> wrote i
message news:eU******** ******@TK2MSFTN GP11.phx.gbl..
If SQL Server, you can do it in your statement
, 'image'+imageTy pe+'.gif' As ImageNam
--

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

Think Outside the Box
*************** *************** *************** *************** *********
"C Newby" <ca*@democracyd ata.com> wrote in messag
news:u8******** ******@tk2msftn gp13.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*******@disc ussions.microso ft.com> wrote in message
news:C6******** *************** ***********@mic rosoft.com...
You can also write a function in your databinding expression for the image cell, e.g. imageurl (or src)=<%# GetMyImage(parm s) %>, 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.netNoS pamM> wrote in message news:eU******** ******@TK2MSFTN GP11.phx.gbl...
> If SQL Server, you can do it in your statement:
>> , 'image'+imageTy pe+'.gif' As ImageName
>> -- > Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>> *************** *************** *************** *************** **********
> Think Outside the Box!
> *************** *************** *************** *************** **********
> "C Newby" <ca*@democracyd ata.com> wrote in message
> news:u8******** ******@tk2msftn gp13.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:BoundColum n DataField="Some thing" HeaderText="Som ething"
DataFormatStrin g="<%=getSometh ing({0})%>"></asp:BoundColumn >

which renders:
<td><%=getSomet hing( 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*******@disc ussions.microso ft.com> wrote in message
news:C6******** *************** ***********@mic rosoft.com...
You can also write a function in your databinding expression for the image cell, e.g. imageurl (or src)=<%# GetMyImage(parm s) %>, 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.netNoS pamM> wrote in message news:eU******** ******@TK2MSFTN GP11.phx.gbl...
> If SQL Server, you can do it in your statement:
>> , 'image'+imageTy pe+'.gif' As ImageName
>> -- > Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
>> *************** *************** *************** *************** **********
> Think Outside the Box!
> *************** *************** *************** *************** **********
> "C Newby" <ca*@democracyd ata.com> wrote in message
> news:u8******** ******@tk2msftn gp13.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.datai tem("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:TemplateCo lumn HeaderText="My Picture Column"><itemte mplate><img src='<%# GetMyPicture(co ntainer.dataite m("cs_key")) %>'/> (don't forget the '#'
</itemtemplate></asp:TemplateCol umn

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 "...GetMyPictur e 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:BoundColum n DataField="Some thing" HeaderText="Som ething
DataFormatStrin g="<%=getSometh ing({0})%>"></asp:BoundColumn

which renders
<td><%=getSomet hing( 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*******@disc ussions.microso ft.com> wrote in messag
news:C6******** *************** ***********@mic rosoft.com..
You can also write a function in your databinding expression for the imag cell, e.g. imageurl (or src)=<%# GetMyImage(parm s) %>, 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.netNoS pamM wrote i
message news:eU******** ******@TK2MSFTN GP11.phx.gbl..
If SQL Server, you can do it in your statement
, 'image'+imageTy pe+'.gif' As ImageNam
-- Gregory A. Beame
MVP; MCP: +I, SE, SD, DB
*************** *************** *************** *************** *********
Think Outside the Box

*************** *************** *************** *************** *********
"C Newby" <ca*@democracyd ata.com> wrote in messag
news:u8******** ******@tk2msftn gp13.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.datai tem("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:TemplateCo lumn HeaderText="My Picture Column"><itemte mplate><img src='<%# GetMyPicture(co ntainer.dataite m("cs_key")) %>'/> (don't forget the '#'
</itemtemplate></asp:TemplateCol umn

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 "...GetMyPictur e 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:BoundColum n DataField="Some thing" HeaderText="Som ething
DataFormatStrin g="<%=getSometh ing({0})%>"></asp:BoundColumn

which renders
<td><%=getSomet hing( 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*******@disc ussions.microso ft.com> wrote in messag
news:C6******** *************** ***********@mic rosoft.com..
You can also write a function in your databinding expression for the imag cell, e.g. imageurl (or src)=<%# GetMyImage(parm s) %>, 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.netNoS pamM wrote i
message news:eU******** ******@TK2MSFTN GP11.phx.gbl..
If SQL Server, you can do it in your statement
, 'image'+imageTy pe+'.gif' As ImageNam
-- Gregory A. Beame
MVP; MCP: +I, SE, SD, DB
*************** *************** *************** *************** *********
Think Outside the Box

*************** *************** *************** *************** *********
"C Newby" <ca*@democracyd ata.com> wrote in messag
news:u8******** ******@tk2msftn gp13.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.data item("myField") " didn't work for me, I ended up using:
"DataBinder.Eva l(Container, "DataItem.myFie ld")". Any thoughts on that?

Hey again, I really apreciate the help//

"Bill Borg" <an*******@disc ussions.microso ft.com> wrote in message
news:80******** *************** ***********@mic rosoft.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.datai tem("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:TemplateCo lumn HeaderText="My Picture Column"><itemte mplate><img src='<%# GetMyPicture(co ntainer.dataite m("cs_key")) %>'/> (don't forget the
'#') </itemtemplate></asp:TemplateCol umn>
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 "...GetMyPictur e 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:BoundColum n DataField="Some thing" HeaderText="Som ething"
DataFormatStrin g="<%=getSometh ing({0})%>"></asp:BoundColumn >

which renders:
<td><%=getSomet hing( 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*******@disc ussions.microso ft.com> wrote in message
news:C6******** *************** ***********@mic rosoft.com...
> You can also write a function in your databinding expression for the image
cell, e.g. imageurl (or src)=<%# GetMyImage(parm s) %>, 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.netNoS pamM>
wrote in
> message news:eU******** ******@TK2MSFTN GP11.phx.gbl...
>> If SQL Server, you can do it in your statement:
>>> , 'image'+imageTy pe+'.gif' As ImageName
>>> --
>> Gregory A. Beamer
>> MVP; MCP: +I, SE, SD, DBA
>>>

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

*************** *************** *************** *************** **********
>> "C Newby" <ca*@democracyd ata.com> wrote in message
>> news:u8******** ******@tk2msftn gp13.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.data item("myField") " didn't work for me, I ended up using:
"DataBinder.Eva l(Container, "DataItem.myFie ld")". Any thoughts on that?

Hey again, I really apreciate the help//

"Bill Borg" <an*******@disc ussions.microso ft.com> wrote in message
news:80******** *************** ***********@mic rosoft.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.datai tem("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:TemplateCo lumn HeaderText="My Picture Column"><itemte mplate><img src='<%# GetMyPicture(co ntainer.dataite m("cs_key")) %>'/> (don't forget the
'#') </itemtemplate></asp:TemplateCol umn>
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 "...GetMyPictur e 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:BoundColum n DataField="Some thing" HeaderText="Som ething"
DataFormatStrin g="<%=getSometh ing({0})%>"></asp:BoundColumn >

which renders:
<td><%=getSomet hing( 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*******@disc ussions.microso ft.com> wrote in message
news:C6******** *************** ***********@mic rosoft.com...
> You can also write a function in your databinding expression for the image
cell, e.g. imageurl (or src)=<%# GetMyImage(parm s) %>, 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.netNoS pamM>
wrote in
> message news:eU******** ******@TK2MSFTN GP11.phx.gbl...
>> If SQL Server, you can do it in your statement:
>>> , 'image'+imageTy pe+'.gif' As ImageName
>>> --
>> Gregory A. Beamer
>> MVP; MCP: +I, SE, SD, DBA
>>>

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

*************** *************** *************** *************** **********
>> "C Newby" <ca*@democracyd ata.com> wrote in message
>> news:u8******** ******@tk2msftn gp13.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
1612
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 on the server and not in sql server, however, the name and path of the images are stored with the text in sql server. I don't have a clue on how to load the images into the grid, so can someone please advise on how i can get started with this? ...
7
269
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 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//
7
14806
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 want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
3
1717
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 the dropdown box ok when it was outside of the gridview for (int i = 0; i <= listcategory.Count - 1; i++) { ddl.Items.Add(listcategory.Description);
0
8680
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9030
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.