3

I have a column that has an ImageButton. my database field has bit data type. I want when my record has true value in that column show True.jpg and my command become MakeFalse and when it has false value show False.jpg and my command become MakeTrue. How I can do this?Is it possible to do it with one TemplateField?

thanks

Mubarek
  • 2,691
  • 1
  • 15
  • 24
Arian
  • 12,793
  • 66
  • 176
  • 300

2 Answers2

3

You could include two ImageButtons in a TemplateField and evaluate Visible from your bit_field

<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>     
</asp:TemplateField>

I'm not sure how you'd want your Command to tie in.

Brissles
  • 3,833
  • 23
  • 31
3

This is the remaining part of the above Brissles code

<asp:TemplateField ShowHeader="False">
  <ItemTemplate>
    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
    CommandName="Select" Text='<%#(bool)Eval("bit_field")? "Make False":"Make True" %>'>  
    </asp:LinkButton>
  </ItemTemplate>
 </asp:TemplateField>
Mubarek
  • 2,691
  • 1
  • 15
  • 24