replace a value with a graphic/icon in a datagrid population??

S

simon

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>
 
E

Elton Wang

Hi Simon,

In VS2005 and .net 2.0, I suppose it's better to use GridView. If GridView
control you can use ImageField to show icons. And in RowDataBound event to
check condition, if 0 set ImageField visible to false.

Using datagrid is similar. Use a TemplateColumn and ImageControl, And in
datagrid_ItemDataBound event to check condition.

HTH
 
S

simon

Hello,
thank you for the reply. that is a good tip and i will save it for
the future. what i ened up doing, which was like your second
suggestion, was the following....

<asp:templatecolumn headertext="Title">
<itemtemplate>
<asp:image id="Image1" runat="server"
imageurl='<%#"/app/images/" &
iif((eval("field")=1),"icon.gif","blank_icon.gif")%>' />
</itemtemplate>
</asp:templatecolumn>

thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top