How to change and image?

M

Miguel Dias Moura

Hello,

i know how to hide a table according to a condition:
<table runat="server" visible='<%# dataSetBibliotecas.FieldValue("Titulo",
Container) <> "" %>'...

Now I am trying to change the image file as follows:
- Show the image "yes.gif" if the value of a dynamic field is equal to
"YES";
- Show the image "no.gif" if the value of a dynamic field is equal to "NO".

Do you think this is possible? Can you help me out?

Thank You,
Miguel
 
K

Ken Cox [Microsoft MVP]

Hi Miguel,

Don't forget that you can use an IIF inside a template item. In the
following code, the IIF checks the value of the "Boolean" field and returns
the English or French button depending on whether the value is true or
false. You could probably adapt this technique to your Yes and No image
locations.

Does this help?

Ken
Microsoft MVP [ASP.NET]


<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image id="Image1" runat="server"
ImageUrl='<%# IIf(DataBinder.Eval(Container,
"DataItem.Boolean"),"http://www.gc.ca/images/englishbt.gif","http://www.gc.ca/images/francaisbt.gif")
%>'>
</asp:Image>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Function CreateDataSource() As ICollection
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("PercentValue", GetType(Double)))
dt.Columns.Add _
(New DataColumn("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 0.23 * (i + 1)
If i = 5 Then
dr(3) = False
Else
dr(3) = True
End If

dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Return dv
End Function 'CreateDataSource
 
M

Miguel Dias Moura

Thanks,

i will try it now.

P.S: about not answering to some posts - sometimes they disapear in my
Outlook. The oldest ones. So when i am going to check them out they are not
there.

Ken Cox said:
Hi Miguel,

Don't forget that you can use an IIF inside a template item. In the
following code, the IIF checks the value of the "Boolean" field and returns
the English or French button depending on whether the value is true or
false. You could probably adapt this technique to your Yes and No image
locations.

Does this help?

Ken
Microsoft MVP [ASP.NET]


<asp:DataGrid id="DataGrid1" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image id="Image1" runat="server"
ImageUrl='<%# IIf(DataBinder.Eval(Container,
"DataItem.Boolean"),"http://www.gc.ca/images/englishbt.gif","http://www.gc.c
a/images/francaisbt.gif")
%>'>
</asp:Image>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
DataGrid1.DataSource = CreateDataSource()
DataGrid1.DataBind()
End If
End Sub

Function CreateDataSource() As ICollection
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn _
("PercentValue", GetType(Double)))
dt.Columns.Add _
(New DataColumn("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 0.23 * (i + 1)
If i = 5 Then
dr(3) = False
Else
dr(3) = True
End If

dt.Rows.Add(dr)
Next i
Dim dv As New DataView(dt)
Return dv
End Function 'CreateDataSource



Miguel Dias Moura said:
Hello,

i know how to hide a table according to a condition:
<table runat="server" visible='<%# dataSetBibliotecas.FieldValue("Titulo",
Container) <> "" %>'...

Now I am trying to change the image file as follows:
- Show the image "yes.gif" if the value of a dynamic field is equal to
"YES";
- Show the image "no.gif" if the value of a dynamic field is equal to
"NO".

Do you think this is possible? Can you help me out?

Thank You,
Miguel
 

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,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top