Home
    Shop
    Advertise
    Write For Us
    Affiliate
    Newsletter
    Contact


How 1/0 In Database To Show As Yes/No Column In GridView?

Instead of showing 1 or 0 from database, you can show more user friendly "yes" and "no" in GridView. To achieve this, you need to use additional code. You need to call outside function, like in this case:

<asp:DataGrid id="dgContacts" runat="server" AutoGenerateColumns="False">
<Columns>
     <asp:TemplateColumn HeaderText="Married">
     <ItemTemplate>
          <%#MarriageStatus(bool.Parse(DataBinder.Eval(Container.DataItem,"MarriageStatus" ).ToString()))%>
     </ItemTemplate>
     </asp:TemplateColumn>
</Columns>
</asp:DataGrid>

On the server side, this MarriageStatus function will return yes or no, depending of 1 or 0 value in database.

[ C# ]

protected string MarriageStatus(bool Married)
{
    if (Married == true)
        return "Yes";
    else
        return "No";
}

[ VB.NET ]

Protected Function MarriageStatus(ByVal Married As Boolean) As String
    If Married = True Then
        MarriageStatus = "Yes"
    Else
        MarriageStatus = "No"
    End If
End Function



Related articles:

1. Storing Images to Database and Retrieving to GridView
2. GridView Hidden Column Problem (And Two Common Solutions)

FAQ toolbar: Submit FAQ  |  Tell A Friend  |  Add to favorites  |  Feedback



Copyright © 2002-2008 Bean Software. All rights reserved.