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

Home Posts Topics Members FAQ

Replace a value wiith a graphic in a datagrid?

hello,
i am displaying a dataset in a datagrid, for one of the values being
displayed it either comes back as a 1 or a 0, which is currently bound
to a column in the datagrid
what i'd like to do is that if the value equals 1, replace that value
with a small icon image. if it equals 0 then have nothing display in
that column.
can this be done? please bear in mind that i'm relatively new to
asp.net. i'm currently using VS2005 and .net 2.0
thank you for any help

source....

in codebehind:
ResultsGrid.Dat aBind()

in aspx page:
<asp:BoundColum n DataField="Pref Picked" HeaderText="Pre ference
Selected">
<HeaderStyle ForeColor="#000 000"></HeaderStyle>
<ItemStyle CssClass="bodyt ext"></ItemStyle>
</asp:BoundColumn >

Mar 21 '06 #1
4 1599
Hi Simon,

For that, I'd use a template column, some inline code and an iif()
statement. Depending on the value from the field, you reference a different
image.

Here's an example that should get you started.

Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]

<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">
Function CreateDataSourc e() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add( New Data.DataColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New Data.DataColumn _
("StringValu e", GetType(String) ))
dt.Columns.Add( New Data.DataColumn _
("CurrencyValue ", GetType(Double) ))
dt.Columns.Add( New Data.DataColumn _
("Boolean", GetType(Boolean )))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
If Not IsPostBack Then
dg.DataSource = CreateDataSourc e()
dg.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dg" runat="server"
autogeneratecol umns="False">
<columns>
<asp:templateco lumn headertext="Lan guage">
<itemtemplate >
<asp:image id="Image1" runat="server"
imageurl='<%#"h ttp://www.gc.ca/images/" &
iif((eval("bool ean")=true),"fr ancaisbt.gif"," englishbt.gif") %>' />
</itemtemplate>
</asp:templatecol umn>
<asp:templateco lumn>
<itemtemplate >
<asp:label id="lbl" runat="server" text='<%#
eval("boolean") %>'></asp:label>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
<asp:label id="Label1" runat="server"
text="Label"></asp:label></div>
</form>
</body>
</html>

"simon" <me@here.com> wrote in message
news:nn******** *************** *********@4ax.c om...
hello,
i am displaying a dataset in a datagrid, for one of the values being
displayed it either comes back as a 1 or a 0, which is currently bound
to a column in the datagrid
what i'd like to do is that if the value equals 1, replace that value
with a small icon image. if it equals 0 then have nothing display in
that column.
can this be done? please bear in mind that i'm relatively new to
asp.net. i'm currently using VS2005 and .net 2.0
thank you for any help

source....

in codebehind:
ResultsGrid.Dat aBind()

in aspx page:
<asp:BoundColum n DataField="Pref Picked" HeaderText="Pre ference
Selected">
<HeaderStyle ForeColor="#000 000"></HeaderStyle>
<ItemStyle CssClass="bodyt ext"></ItemStyle>
</asp:BoundColumn >

Mar 21 '06 #2
wow. thank you for that great example.
basically, all i'd need is this section:

<asp:templateco lumn headertext="Lan guage">
<itemtemplate >
<asp:image id="Image1" runat="server"
imageurl='<%#"h ttp://www.gc.ca/images/" &
iif((eval("bool ean")=true),"fr ancaisbt.gif"," englishbt.gif") %>' />
</itemtemplate>
</asp:templatecol umn>

to evaluate the the value and switch between the image and the null
image, correct? i'll try that out tonight and let you all know how it
turns out. thank you very much.
On Mon, 20 Mar 2006 22:54:24 -0800, "Ken Cox - Microsoft MVP"
<BA**********@h otmail.com> wrote:
Hi Simon,

For that, I'd use a template column, some inline code and an iif()
statement. Depending on the value from the field, you reference a different
image.

Here's an example that should get you started.

Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]

<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">
Function CreateDataSourc e() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add( New Data.DataColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New Data.DataColumn _
("StringValu e", GetType(String) ))
dt.Columns.Add( New Data.DataColumn _
("CurrencyValue ", GetType(Double) ))
dt.Columns.Add( New Data.DataColumn _
("Boolean", GetType(Boolean )))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
If Not IsPostBack Then
dg.DataSource = CreateDataSourc e()
dg.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dg" runat="server"
autogenerateco lumns="False">
<columns>
<asp:templateco lumn headertext="Lan guage">
<itemtemplate >
<asp:image id="Image1" runat="server"
imageurl='<%#" http://www.gc.ca/images/" &
iif((eval("boo lean")=true),"f rancaisbt.gif", "englishbt.gif" )%>' />
</itemtemplate>
</asp:templatecol umn>
<asp:templateco lumn>
<itemtemplate >
<asp:label id="lbl" runat="server" text='<%#
eval("boolean" )%>'></asp:label>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
<asp:label id="Label1" runat="server"
text="Label" ></asp:label></div>
</form>
</body>
</html>

"simon" <me@here.com> wrote in message
news:nn******* *************** **********@4ax. com...
hello,
i am displaying a dataset in a datagrid, for one of the values being
displayed it either comes back as a 1 or a 0, which is currently bound
to a column in the datagrid
what i'd like to do is that if the value equals 1, replace that value
with a small icon image. if it equals 0 then have nothing display in
that column.
can this be done? please bear in mind that i'm relatively new to
asp.net. i'm currently using VS2005 and .net 2.0
thank you for any help

source....

in codebehind:
ResultsGrid.Dat aBind()

in aspx page:
<asp:BoundColum n DataField="Pref Picked" HeaderText="Pre ference
Selected">
<HeaderStyle ForeColor="#000 000"></HeaderStyle>
<ItemStyle CssClass="bodyt ext"></ItemStyle>
</asp:BoundColumn >


Mar 21 '06 #3
that worked perfectly! thank you very much!!

On Tue, 21 Mar 2006 07:56:24 -0500, simon <me@here.com> wrote:
wow. thank you for that great example.
basically, all i'd need is this section:

<asp:templatec olumn headertext="Lan guage">
<itemtemplate >
<asp:image id="Image1" runat="server"
imageurl='<%#" http://www.gc.ca/images/" &
iif((eval("boo lean")=true),"f rancaisbt.gif", "englishbt.gif" )%>' />
</itemtemplate>
</asp:templatecol umn>

to evaluate the the value and switch between the image and the null
image, correct? i'll try that out tonight and let you all know how it
turns out. thank you very much.
On Mon, 20 Mar 2006 22:54:24 -0800, "Ken Cox - Microsoft MVP"
<BA**********@ hotmail.com> wrote:
Hi Simon,

For that, I'd use a template column, some inline code and an iif()
statement. Depending on the value from the field, you reference a different
image.

Here's an example that should get you started.

Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]

<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">
Function CreateDataSourc e() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add( New Data.DataColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New Data.DataColumn _
("StringValu e", GetType(String) ))
dt.Columns.Add( New Data.DataColumn _
("CurrencyValue ", GetType(Double) ))
dt.Columns.Add( New Data.DataColumn _
("Boolean", GetType(Boolean )))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
If Not IsPostBack Then
dg.DataSource = CreateDataSourc e()
dg.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dg" runat="server"
autogeneratec olumns="False">
<columns>
<asp:templateco lumn headertext="Lan guage">
<itemtemplate >
<asp:image id="Image1" runat="server"
imageurl='<%# "http://www.gc.ca/images/" &
iif((eval("bo olean")=true)," francaisbt.gif" ,"englishbt.gif ")%>' />
</itemtemplate>
</asp:templatecol umn>
<asp:templateco lumn>
<itemtemplate >
<asp:label id="lbl" runat="server" text='<%#
eval("boolean ")%>'></asp:label>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
<asp:label id="Label1" runat="server"
text="Label"> </asp:label></div>
</form>
</body>
</html>

"simon" <me@here.com> wrote in message
news:nn****** *************** ***********@4ax .com...
hello,
i am displaying a dataset in a datagrid, for one of the values being
displayed it either comes back as a 1 or a 0, which is currently bound
to a column in the datagrid
what i'd like to do is that if the value equals 1, replace that value
with a small icon image. if it equals 0 then have nothing display in
that column.
can this be done? please bear in mind that i'm relatively new to
asp.net. i'm currently using VS2005 and .net 2.0
thank you for any help

source....

in codebehind:
ResultsGrid.Dat aBind()

in aspx page:
<asp:BoundColum n DataField="Pref Picked" HeaderText="Pre ference
Selected">
<HeaderStyle ForeColor="#000 000"></HeaderStyle>
<ItemStyle CssClass="bodyt ext"></ItemStyle>
</asp:BoundColumn >


Mar 21 '06 #4
Thanks for reporting back!

Feedback helps others who are searching through old answers to know that a
proposed solution was on the right track.

Ken

"simon" <me@here.com> wrote in message
news:vl******** *************** *********@4ax.c om...
that worked perfectly! thank you very much!!

On Tue, 21 Mar 2006 07:56:24 -0500, simon <me@here.com> wrote:
wow. thank you for that great example.
basically, all i'd need is this section:

<asp:template column headertext="Lan guage">
<itemtemplate >
<asp:image id="Image1" runat="server"
imageurl='<%# "http://www.gc.ca/images/" &
iif((eval("bo olean")=true)," francaisbt.gif" ,"englishbt.gif ")%>' />
</itemtemplate>
</asp:templatecol umn>

to evaluate the the value and switch between the image and the null
image, correct? i'll try that out tonight and let you all know how it
turns out. thank you very much.
On Mon, 20 Mar 2006 22:54:24 -0800, "Ken Cox - Microsoft MVP"
<BA********** @hotmail.com> wrote:
Hi Simon,

For that, I'd use a template column, some inline code and an iif()
statement. Depending on the value from the field, you reference a
different
image.

Here's an example that should get you started.

Let us know if it helps?

Ken
Microsoft MVP [ASP.NET]

<%@ page language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">

<script runat="server">
Function CreateDataSourc e() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add( New Data.DataColumn _
("IntegerValue" , GetType(Int32)) )
dt.Columns.Add( New Data.DataColumn _
("StringValu e", GetType(String) ))
dt.Columns.Add( New Data.DataColumn _
("CurrencyValue ", GetType(Double) ))
dt.Columns.Add( New Data.DataColumn _
("Boolean", GetType(Boolean )))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArg s)
If Not IsPostBack Then
dg.DataSource = CreateDataSourc e()
dg.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dg" runat="server"
autogenerate columns="False" >
<columns>
<asp:templateco lumn headertext="Lan guage">
<itemtemplate >
<asp:image id="Image1" runat="server"
imageurl='<% #"http://www.gc.ca/images/" &
iif((eval("b oolean")=true), "francaisbt.gif ","englishbt.gi f")%>' />
</itemtemplate>
</asp:templatecol umn>
<asp:templateco lumn>
<itemtemplate >
<asp:label id="lbl" runat="server" text='<%#
eval("boolea n")%>'></asp:label>
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
<asp:label id="Label1" runat="server"
text="Label" ></asp:label></div>
</form>
</body>
</html>

"simon" <me@here.com> wrote in message
news:nn***** *************** ************@4a x.com...
hello,
i am displaying a dataset in a datagrid, for one of the values being
displayed it either comes back as a 1 or a 0, which is currently bound
to a column in the datagrid
what i'd like to do is that if the value equals 1, replace that value
with a small icon image. if it equals 0 then have nothing display in
that column.
can this be done? please bear in mind that i'm relatively new to
asp.net. i'm currently using VS2005 and .net 2.0
thank you for any help

source....

in codebehind:
ResultsGrid.Dat aBind()

in aspx page:
<asp:BoundColum n DataField="Pref Picked" HeaderText="Pre ference
Selected">
<HeaderStyle ForeColor="#000 000"></HeaderStyle>
<ItemStyle CssClass="bodyt ext"></ItemStyle>
</asp:BoundColumn >

Mar 22 '06 #5

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

Similar topics

0
2653
by: Amber | last post by:
There are times when you will need to highlight or otherwise modify the contents of a particular DataGrid row-column value based upon the value in the column. In this example we will select the CompanyName, ContactName, and ContactTitle columns from the Customers table in the Northwind database. Whenever the value of ContactTitle equals "Owner" we will change the font color to red. We can do this by using an ItemTemplate where we have...
7
1088
by: Kent P. Iler | last post by:
Hi, I'm creating a website where I need to pull data from a database, and display it on a page. This isn't a place where a repeater or datagrid makes sense. I was using labels and setting the text equal to the values that I needed to display. That works OK in most places, but in areas where there are memo fields requiring multiple lines, a label doesn't cut it. What would be the best thing to use instead of a label, and allow the...
2
1259
by: Don Buchanan | last post by:
I'm trying to get a single column DataGrid to display a graphic. I set up the DataGrid template to display and image. This is what I've tried based on the example I found: Dim dgiItem As DataGridItem For Each dgiItem In DataGrid1.Items With DirectCast(dgiItem.FindControl("Image1"), WebControls.Image)
2
2170
by: TB | last post by:
Before displaying the result of a table called "people" in a datagrid called "mydatagrid", I need to modify the content of a column called "moreinfo" in the in-memory datatable (but not the corresponding table of the database). I was thinking of doing something like this: Dim strSQL as string = "Select ID, firstname, lastname, moreinfo from people order by lastname" Dim myConnection As MySqlConnection = New
3
2999
by: Roy W. Andersen | last post by:
Hi, I need to do some replace-calls on certain strings in order to replace smiley glyphs and other keywords with graphical icons on the client. Unfortunately, my knowledge of regular expressions is somewhat limited to say the least, so I'm struggling with making it work as I wand. What I have is an associative array like this: smileys = 'smile.gif'; smileys = 'sad.gif';
2
1596
by: sanju | last post by:
Hi, I am struggling to replace a bit value 'True' or 'False' with a image true.gif or false.gif and bind it to a repeater control. I am getting values 'true' or 'false' depending on whether user is logged in or not(with asp.net membership provider) Getting true or false with this <%# Membership.GetUser(Eval("UserID")).IsOnline % and
1
1422
by: zafar | last post by:
I need to replace a cell value in grid e.g i have field "user_gender" of data type int where 1 means male and 0 means female. i did not make parent table for "gender", because there is only 2 possible records in table. i am assuming 1 and 0 as male and female. i need; when data is retrieved from database all 0's must be replaced with "Female" and all 1's must be replaced with "Male". One solution is this; that we use counter loop and...
3
2735
by: Eric Layman | last post by:
Hi, I've saved data into the db by doing a replace() on single quote. Right now on data display on a datagrid, it shows double single quote. How do I make changes during run time of datagrid so that the double single quote will be replaced as single quote? Pls advise.
6
7259
by: herzog | last post by:
Hi, I am using C# to a draw a graphic on a memory bitmap. I then extract the color information of every pixel of the bitmap. I do this with Bitmap.GetPixel(). The trouble I'm having is that I need Bitmap.GetPixel() to always return pure RGB values -- ones that always have an alpha value of 255. This is because I need to reproduce the graphic in a different environment that does not have alpha values. I realize I can get...
0
8683
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
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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
8902
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
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4372
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
4623
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

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.