Using the ternary operator when binding data using eval ()

Source: Internet
Author: User

Asp. NET-bonding data "<% #Eval (" Sex ")%>" using ternary operators:
<%# (Eval ("Sex", "{0}") = = "01")? "Male": "Female"%>



<%# (Convert.ToInt32 (Eval ("Nowdate", "{0}")) >60)? Convert.ToInt32 (eval ("Nowdate"))/60+ "Hour Ago": eval ("Nowdate"). ToString () + "minutes ago"%><span class= "Style3" > from Youku </span></td>


Imageurl= ' <%# (Eval ("Use_pic", "{0}"). ToString () = = "Null")? "Head/head.png": Eval ("Use_pic")%> '

The extra length of data binding is replaced by "...":

<asp:linkbutton id= "Linkmessage" forecolor= "Black" runat= "server" text= ' <% #Eval ("Newstitle"). ToString (). Length>10? Eval ("Newstitle"). ToString (). Substring (0,10) + "...": Eval ("Newstitle")%> '/>

Eval Binding method:

<asp:templatefield headertext= "paid status" >
<ItemTemplate>
<asp:label runat= "Server" id= "lbpaystatus" text= ' <% #BLL. Orderbll.getpaystatus (Convert.ToInt32 (Eval ("id")))%> '/>
</ItemTemplate>
</asp:TemplateField>

Multi-Conditional binding:

<asp:templatefield headertext= "First Instance results" >
<ItemTemplate>
<% #Eval ("Hg_a"). ToString () = = "1"? " Pass ": Eval (" Hg_a "). ToString () = = "2"? " Do not pass ":" "%>
</ItemTemplate>
</asp:TemplateField>

Using the ternary operator when binding data using eval ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.