469,926 Members | 1,791 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

How to change and image?

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
Nov 18 '05 #1
3 1697
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

"Miguel Dias Moura" <we****@27NOSPAMlamps.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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


Nov 18 '05 #2
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 [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:#J**************@TK2MSFTNGP10.phx.gbl...
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" <we****@27NOSPAMlamps.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Nov 18 '05 #3
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 [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:#J**************@TK2MSFTNGP10.phx.gbl...
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" <we****@27NOSPAMlamps.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Irvin Amoraal | last post: by
1 post views Thread by Spike | last post: by
2 posts views Thread by Tjerk | last post: by
2 posts views Thread by Ben | last post: by
1 post views Thread by Anthony Boudouvas | last post: by
6 posts views Thread by ruca | last post: by
8 posts views Thread by miladhatam | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.