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>