Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

Comparing the value from Item template,it should be compare with the string.
ASP.NET
  <itemtemplate>
  <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false" 
             CommandArgument="<% #  Container.DataItemIndex %>" CommandName="EVA" 
             ImageUrl="~/Images/cross.gif" 
             Visible='<%# Eval("EvaluationComplete") = 'NO' %>' />
 
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false" 
             CommandArgument="<% #  Container.DataItemIndex %>" CommandName="EVA" 
             ImageUrl="~/Images/tick.gif" 
             Visible='<%# Eval("EvaluationComplete") = 'YES' %>' />
  </itemtemplate>
Posted
Updated 31-Aug-11 20:37pm
v2
Comments
Prerak Patel 1-Sep-11 2:37am    
Use code block for code segment.

better way to do your problem is rename your image name as YES.gif instead of tick.gif and NO.gif instead of cross.gif

and the write coding as

ASP.NET
<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="false" 
             CommandArgument="<% #  Container.DataItemIndex %>" CommandName="EVA" 
             ImageUrl='<%"~/Images/"+ Eval("EvaluationComplete")+".gif" %>'
            />


//logic

it will call the corresponding images based on the values in database. no need to set visible true and false
 
Share this answer
 
v2
Comments
RaisKazi 1-Sep-11 3:15am    
My 5 for better alternate solution.
Abhijit Jana 1-Sep-11 4:32am    
This is an alternative solution. In my point of view, it's not better solution, as Renaming images might have cascading effects in overall application.
Abhijit Jana 1-Sep-11 4:22am    
Why to Rename Images ? Do you think it's a better solution ? What will be the cascading effects of this, if my image is used in "n" number of different place of the same application ? :)
You can do Conditional Binding with Binding Expression while using Eval or Bind Expression. Try the following way.
This will work for you !
XML
<asp:TemplateField>
             <ItemTemplate>
                 <asp:Image ImageUrl='<%# "/Images/" + (Convert.ToBoolean(Eval("EvaluationComplete")) ? "tick" : "cross") + ".png" %>' runat="server" />
             </ItemTemplate>
         </asp:TemplateField>


EvaluationComplete could either True or False and based on the during binding image will change. You can do the same thing in Code Behind as well. But this is going to be good way to handle.
You can check out the output here as well Output[^]

Hope this helps !
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900