How To change Command Text and ImageButton of ItemTemplate in TemplateField

佐手、 提交于 2020-01-23 10:44:04

问题


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


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/8819879/how-to-change-command-text-and-imagebutton-of-itemtemplate-in-templatefield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!