473,395 Members | 1,343 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,395 software developers and data experts.

picture in data grid based on value

Hello, I am working on a simple email website that is kinda like hotmail...
but the listing of messages is in a data grid data bound to a table called
messages... now one of the columns in the messages data table is called read
if the value is 1 the message is read if 0 then unread... what i want to do
is show an image in the listing based on that value, if 1 then
icn-msg-read.gif will be showed in that column for that message row, if 0
then icn-msg-unread.gif needs to be shown, how would i go about doing this?
thanks!
Nov 18 '05 #1
5 1747
Dynamically create an image tag, or use an Image Control, and dynamically
set its URL.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:eu**************@TK2MSFTNGP09.phx.gbl...
Hello, I am working on a simple email website that is kinda like hotmail... but the listing of messages is in a data grid data bound to a table called
messages... now one of the columns in the messages data table is called read if the value is 1 the message is read if 0 then unread... what i want to do is show an image in the listing based on that value, if 1 then
icn-msg-read.gif will be showed in that column for that message row, if 0
then icn-msg-unread.gif needs to be shown, how would i go about doing this? thanks!

Nov 18 '05 #2
yes, I know that but how would i do this in a data bound grid? i need to
pick which image will be displayed based off the value of the data column...
right now its just a numeric value read from a data bound column like this
<%#DataBinder.Eval(Container.DataItem,"Read")%> which ends up showing true
or false on the data grid because it's a bit value... i wanted to do
something like <img src='<%=
ImagePickFunction(DataBinder.Eval(Container.DataIt em,"Read"))%> but that of
course does not work... how would i do this part of the problem? thanks
Nov 18 '05 #3
Hi Brian,

I think your approach is just correct and you've been very closer to the
solution. We can just do such task by using a custom helper functdion
together with the DataBinder.Eval function. But notice that we should
always put the databinding expression in the <%# %> tag rather than <%=
%> , they're different, below are some reference on these webform
expression syntax:

#Data Binding Expression Syntax
http://msdn.microsoft.com/library/en...abindingExpres
sionSyntax.asp?frame=true

#Web Forms Syntax
http://msdn.microsoft.com/library/en...PageSyntax.asp
?frame=true

As for your situation, first, we define a helper function in the page class:

protected string GetImageUrl(object readFlag)
{
int iRead = (int)readFlag;
if(iRead == 0)
{
return "Unread.gif";
}
else
{
return "Read.gif";
}
}

the helper function take an object param because the
DataBinder.Eval(container, expressioN) will return an object reference. And
since your datacolumn's value is a number value, we cast it to int and
return the proper image url depend on its value. After that, we can apply
it in the page's template together with the DataBinder.Eval expression,
just as below:

<img src='<%# GetImageUrl(DataBinder.Eval(Container.DataItem,"Re adColumn"))
%>'>

How do you think of this? If you have any other ideas, pleas also feel free
to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx



Nov 18 '05 #4
Hello,

That is what I was trying previously, doing it like this

<img src='<%# GetImageUrl(DataBinder.Eval(Container.DataItem,"Re adColumn"))
%>'>

but every time it did, it started poping up with the error with something
similar to object 'container' can not be found
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:8v**************@cpmsftngxa06.phx.gbl...
Hi Brian,

I think your approach is just correct and you've been very closer to the
solution. We can just do such task by using a custom helper functdion
together with the DataBinder.Eval function. But notice that we should
always put the databinding expression in the <%# %> tag rather than <%=
%> , they're different, below are some reference on these webform
expression syntax:

#Data Binding Expression Syntax
http://msdn.microsoft.com/library/en...abindingExpres sionSyntax.asp?frame=true

#Web Forms Syntax
http://msdn.microsoft.com/library/en...PageSyntax.asp ?frame=true

As for your situation, first, we define a helper function in the page class:
protected string GetImageUrl(object readFlag)
{
int iRead = (int)readFlag;
if(iRead == 0)
{
return "Unread.gif";
}
else
{
return "Read.gif";
}
}

the helper function take an object param because the
DataBinder.Eval(container, expressioN) will return an object reference. And since your datacolumn's value is a number value, we cast it to int and
return the proper image url depend on its value. After that, we can apply
it in the page's template together with the DataBinder.Eval expression,
just as below:

<img src='<%# GetImageUrl(DataBinder.Eval(Container.DataItem,"Re adColumn")) %>'>

How do you think of this? If you have any other ideas, pleas also feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx



Nov 18 '05 #5
nevermind, it suddenly works with out changeing any code... odd behavior of
the code..
"Brian Henry" <br**********@newsgroups.nospam> wrote in message
news:uU*************@TK2MSFTNGP11.phx.gbl...
Hello,

That is what I was trying previously, doing it like this

<img src='<%# GetImageUrl(DataBinder.Eval(Container.DataItem,"Re adColumn")) %>'>

but every time it did, it started poping up with the error with something
similar to object 'container' can not be found
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:8v**************@cpmsftngxa06.phx.gbl...
Hi Brian,

I think your approach is just correct and you've been very closer to the
solution. We can just do such task by using a custom helper functdion
together with the DataBinder.Eval function. But notice that we should
always put the databinding expression in the <%# %> tag rather than <%= %> , they're different, below are some reference on these webform
expression syntax:

#Data Binding Expression Syntax

http://msdn.microsoft.com/library/en...abindingExpres
sionSyntax.asp?frame=true

#Web Forms Syntax

http://msdn.microsoft.com/library/en...PageSyntax.asp
?frame=true

As for your situation, first, we define a helper function in the page

class:

protected string GetImageUrl(object readFlag)
{
int iRead = (int)readFlag;
if(iRead == 0)
{
return "Unread.gif";
}
else
{
return "Read.gif";
}
}

the helper function take an object param because the
DataBinder.Eval(container, expressioN) will return an object reference.

And
since your datacolumn's value is a number value, we cast it to int and
return the proper image url depend on its value. After that, we can apply it in the page's template together with the DataBinder.Eval expression,
just as below:

<img src='<%#

GetImageUrl(DataBinder.Eval(Container.DataItem,"Re adColumn"))
%>'>

How do you think of this? If you have any other ideas, pleas also feel

free
to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx




Nov 18 '05 #6

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

Similar topics

5
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to...
12
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
0
by: Brian Henry | last post by:
Hello, I am working on a simple email website that is kinda like hotmail... but the listing of messages is in a data grid data bound to a table called messages... now one of the columns in the...
3
by: pmud | last post by:
Hi, I have a web page (asp.net, code:c#). I havean html table with text boxes. Based on the user input , records are displayed in the data grid below it. Now the datagrid has a large no. of...
1
by: Josh | last post by:
Using Visual Studio 2003, C#, .NET 1.1. I have a web form with a few textboxes, a couple of dropdown lists, and a data grid. The data grid is populated from a SQL stored procedure. The user...
5
by: coolminded | last post by:
hi everyone i have a problem, i just export the data from data grid to the word file, but now the problem is i want to insert the picture in the word with the path name in the grid. for ex; i...
3
by: Screaming Eagles 101 | last post by:
Hi, is there an easy way to add a picture(box) to a column in a datagridview ? My first column has a code, ex. 1, 2 or 3 According to these codes I'dd like to add a picture(box) to my second...
1
by: Sheena777 | last post by:
How do you display a picture in the gridview control. I want to display a picture in the grid as one of the values in a row. The url for the image is save a a text value in the grid and data set.
6
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1)...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.