Chitika

Tuesday, November 20, 2012

Display Yes or No Instead of True or False in asp.net

In asp.net when we are working with there are many places where we get Boolean values which we need to show them for the user in user preferred format. 
Usually we will get this situation when binding  data control  with data bound templates.
For example if we have status of the customer .
To show the customer status to the user in grid we write below statement generally.
<ItemTemplate><%#Eval("Status")%></ItemTemplate>

The output for the above statement will be shown either True/ False based on the status.
But what the user expecting is Yes / No  or Active / In-Active it can be any thing which they prefer to use.
To accomplish this the above statement has to be updated as below,

<ItemTemplate><%#Eval("Status" ? "Yes": "No"%></ItemTemplate>

Based on the user preference we can write anything in place of Yes and No, as

<ItemTemplate><%#Eval("Status" ? "Active": "In-Active"%></ItemTemplate>

No comments:

Post a Comment