Gender (0,1) to the (male, female) method summary

Source: Internet
Author: User
Method 1:

Select
Case Sex
When ' 1 ' THEN ' male '
When ' 0 ' THEN ' woman '
ELSE ' no man or woman. haha
End as Sex
From TestName

Method 2:

Processing in RowDataBound

if (Index of e.row.cells[column). Text = = "0")
... {
Index of the e.row.cells[column]. text= "Male";
}
Else
... {
Index of the e.row.cells[column]. text= "female";
}

Method 3: Template column (sex = = "1"?) Male ":" female ")

To use a template column:
< Asp:templatecolumn HeaderText = "Gender" >
< ItemTemplate >
< Asp:label runat = "server" Text = ' <%# databinder.eval (Container, ' dataitem.sex '). ToString () = "1"? Male ":" Female "% > ' id=" Label1 ">
</Asp:label >
</ItemTemplate >
</asp:templatecolumn >


Attention:

If the field is bit <%# (bool) Eval ("Sex")? "Male": "Female"%>
If it is char <%# DataBinder.Eval (Container.DataItem, "Sex"). ToString () = = "1"? Male ":" Female "%>

Method 4: Custom Functions

CS Files: Foreground: Protected   string  showsex (int  temp) ... {
        if  (temp == 1)  .. { 
            return  "Male";}
        else ... {
            return  "female";
        }
    }

  < asp:templatefield  HeaderText = "gender"   >
                                       < ItemTemplate >
                                            < asp:label  ID = "F_sex"  runat = "server"  text = ' <%#  showsex (Convert.ToInt32 (Eval ("F _sex "))  % > ' > ' > </asp:label >
                                       </ItemTemplate >

Reproduced from the Banyan tree under the yang too

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.