1

I have the following line of code which evaluates whether the value is true or false, if its true it will show an image if its false it shows a different one.

<itemTemplate>
<img alt="" id="Img1" 
 src='<%# MyAdmin.GetCheckMark((bool)DataBinder.Eval(Container.DataItem, "ShowImg"))%>' 
 runat="server" /></ItemTemplate>

Can I customize the Eval part in the back end code in c# and then pass a different variable to it for example in C# I want to do

  bool ImgFlag = false;
  if(Entity.ShowImg == false && Entity.SomethingElse == true)
   {
      ImgFlag = true;
   }
  else if(Entity.ShowImg == false && Entity.SomethingElse == false)
  {  
      ImaFlag = false;
  }
  else
  {
      ImgFlag = true;
  }

And then I want to use ImgFlag instead of ShowImg in my GridView on each row, so ImgFlag will determine which flag to show..

Or is there a better way?

The issue is that that eval depends now on two things.. not one as before.

Thank you

Mubarek
  • 2,691
  • 1
  • 15
  • 24
user710502
  • 11,181
  • 29
  • 106
  • 161

2 Answers2

2

This does the trick

<asp:TemplateField ShowHeader="False">
<ItemTemplate>
   <asp:Image runat="server" ImageUrlt='<%#(bool)Eval("bit_field")? "first.jpg":"second.jpg" %>'>  
  </asp:Image>
</ItemTemplate>

Or this

<asp:TemplateField HeaderText="YourField">
<ItemTemplate>
    <asp:ImageButton runat="server" ImageUrl="True.jpg" Visible='<%# (bool)Eval("bit_field") %>' />
    <asp:ImageButton runat="server" ImageUrl="False.jpg" Visible='<%# !(bool)Eval("bit_field") %>' />
</ItemTemplate>     

Found in this question


Community
  • 1
  • 1
Mubarek
  • 2,691
  • 1
  • 15
  • 24
1

Eval actually returns a property, so you can just call it twice for different properties.

Kind of

MyAdmin.GetCheckMark2((bool)DataBinder.Eval(Container.DataItem, "ShowImg"),
         (bool)DataBinder.Eval(Container.DataItem, "SomethingElse"));

may help

the_joric
  • 11,986
  • 6
  • 36
  • 57
  • But how would i be able to condition it.. like i need ShowImg to check if its false and if SomethingElse is True and viceversa – user710502 Feb 01 '12 at 18:07