问题
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