473,465 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Create 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.DataBind()

in aspx page:
<asp:BoundColumn DataField="PrefPicked" HeaderText="Preference
Selected">
<HeaderStyle ForeColor="#000000"></HeaderStyle>
<ItemStyle CssClass="bodytext"></ItemStyle>
</asp:BoundColumn>

Mar 21 '06 #1
4 1586
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.dtd">

<script runat="server">
Function CreateDataSource() 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 _
("StringValue", 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.EventArgs)
If Not IsPostBack Then
dg.DataSource = CreateDataSource()
dg.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dg" runat="server"
autogeneratecolumns="False">
<columns>
<asp:templatecolumn headertext="Language">
<itemtemplate>
<asp:image id="Image1" runat="server"
imageurl='<%#"http://www.gc.ca/images/" &
iif((eval("boolean")=true),"francaisbt.gif","engli shbt.gif")%>' />
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn>
<itemtemplate>
<asp:label id="lbl" runat="server" text='<%#
eval("boolean")%>'></asp:label>
</itemtemplate>
</asp:templatecolumn>
</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.DataBind()

in aspx page:
<asp:BoundColumn DataField="PrefPicked" HeaderText="Preference
Selected">
<HeaderStyle ForeColor="#000000"></HeaderStyle>
<ItemStyle CssClass="bodytext"></ItemStyle>
</asp:BoundColumn>

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

<asp:templatecolumn headertext="Language">
<itemtemplate>
<asp:image id="Image1" runat="server"
imageurl='<%#"http://www.gc.ca/images/" &
iif((eval("boolean")=true),"francaisbt.gif","engli shbt.gif")%>' />
</itemtemplate>
</asp:templatecolumn>

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.dtd">

<script runat="server">
Function CreateDataSource() 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 _
("StringValue", 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.EventArgs)
If Not IsPostBack Then
dg.DataSource = CreateDataSource()
dg.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dg" runat="server"
autogeneratecolumns="False">
<columns>
<asp:templatecolumn headertext="Language">
<itemtemplate>
<asp:image id="Image1" runat="server"
imageurl='<%#"http://www.gc.ca/images/" &
iif((eval("boolean")=true),"francaisbt.gif","engl ishbt.gif")%>' />
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn>
<itemtemplate>
<asp:label id="lbl" runat="server" text='<%#
eval("boolean")%>'></asp:label>
</itemtemplate>
</asp:templatecolumn>
</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.DataBind()

in aspx page:
<asp:BoundColumn DataField="PrefPicked" HeaderText="Preference
Selected">
<HeaderStyle ForeColor="#000000"></HeaderStyle>
<ItemStyle CssClass="bodytext"></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:templatecolumn headertext="Language">
<itemtemplate>
<asp:image id="Image1" runat="server"
imageurl='<%#"http://www.gc.ca/images/" &
iif((eval("boolean")=true),"francaisbt.gif","engl ishbt.gif")%>' />
</itemtemplate>
</asp:templatecolumn>

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.dtd">

<script runat="server">
Function CreateDataSource() 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 _
("StringValue", 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.EventArgs)
If Not IsPostBack Then
dg.DataSource = CreateDataSource()
dg.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dg" runat="server"
autogeneratecolumns="False">
<columns>
<asp:templatecolumn headertext="Language">
<itemtemplate>
<asp:image id="Image1" runat="server"
imageurl='<%#"http://www.gc.ca/images/" &
iif((eval("boolean")=true),"francaisbt.gif","eng lishbt.gif")%>' />
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn>
<itemtemplate>
<asp:label id="lbl" runat="server" text='<%#
eval("boolean")%>'></asp:label>
</itemtemplate>
</asp:templatecolumn>
</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.DataBind()

in aspx page:
<asp:BoundColumn DataField="PrefPicked" HeaderText="Preference
Selected">
<HeaderStyle ForeColor="#000000"></HeaderStyle>
<ItemStyle CssClass="bodytext"></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.com...
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:templatecolumn headertext="Language">
<itemtemplate>
<asp:image id="Image1" runat="server"
imageurl='<%#"http://www.gc.ca/images/" &
iif((eval("boolean")=true),"francaisbt.gif","eng lishbt.gif")%>' />
</itemtemplate>
</asp:templatecolumn>

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.dtd">

<script runat="server">
Function CreateDataSource() 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 _
("StringValue", 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.EventArgs)
If Not IsPostBack Then
dg.DataSource = CreateDataSource()
dg.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dg" runat="server"
autogeneratecolumns="False">
<columns>
<asp:templatecolumn headertext="Language">
<itemtemplate>
<asp:image id="Image1" runat="server"
imageurl='<%#"http://www.gc.ca/images/" &
iif((eval("boolean")=true),"francaisbt.gif","en glishbt.gif")%>' />
</itemtemplate>
</asp:templatecolumn>
<asp:templatecolumn>
<itemtemplate>
<asp:label id="lbl" runat="server" text='<%#
eval("boolean")%>'></asp:label>
</itemtemplate>
</asp:templatecolumn>
</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.DataBind()

in aspx page:
<asp:BoundColumn DataField="PrefPicked" HeaderText="Preference
Selected">
<HeaderStyle ForeColor="#000000"></HeaderStyle>
<ItemStyle CssClass="bodytext"></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
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...
7
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...
2
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...
2
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...
3
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...
2
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...
1
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...
3
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...
6
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...
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
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...
1
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...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.