Yasserzaid’s Weblog

July 1, 2009

Assignment of Yes or No based on value read from DB

Filed under: ASP.Net — yasserzaid @ 6:05 am

Hi

try this example to displayYes or No based on value read from DB

public string ReplaceBitValue(Object obj)  
{  
    string returnValue = string.Empty;  
    if (!string.IsNullOrEmpty(obj.ToString()))  
    {  
        if (obj.ToString() == “1″)  
        {  
            returnValue = “Yes”;  
        }  
        else if (obj.ToString() == “0″)  
        {  
            returnValue = “No”;  
        }  
    }  
    return returnValue;  

<asp:TemplateField HeaderText=”Status”>
     <ItemTemplate>
         <asp:Label ID=”status” runat=”server” Text=’<%# ReplaceBitValue(Eval(“BitField”).ToString()) %>’></asp:Label>
      </ItemTemplate>
</asp:TemplateField>

//— another way —-

C#
<asp:label id=”Label1″ runat=”server” text=’<%# Convert.ToBoolean(Eval(“MyDataField”)) ? “yes” : “no” %>’ />

VB.NET
<asp:label id=”Label1″ runat=”server” text=’<%# IIf(Convert.ToBoolean(Eval(“MyDataField”)), “yes”, “no”) %>’ />

//— another way —-

<asp:Label ID=”lblEnrollDate” runat=”server”
Text=’<%# IIF(CONVERT.ToString(Eval(“IsEnrolled”))=”True”, “Yes”, “No”) %>’>
</asp:Label>

Hope this helps

Good Luck

1 Comment »

  1. Dear Friends,

    I hope you are doing well. I have launched a web site http://www.codegain.com and it is basically aimed C#,JAVA,VB.NET,ASP.NET,AJAX,Sql Server,Oracle,WPF,WCF and etc resources, programming help, articles, code snippet, video demonstrations and problems solving support. I would like to invite you as an author and a supporter. Looking forward to hearing from you and hope you will join with us soon.

    Please forward this email to all of your friends who are related IT. Send to us your feed about site also.

    Thank you
    RRaveen
    Founder CodeGain.com

    Comment by RRaveen — July 2, 2009 @ 10:05 am


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.