我希望 ASP.NET 在表中列出 Bool 数据类型,true 或 false,如果为真则为男性,如果为假则为女性

问题描述 投票:0回答:2

我试着给病人摆桌子。我使用 entityframework 从数据库中提取数据。但我想让性别数据为男性,如果为真,则为女性,如果为假

aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DentistAppointmentSystem.Entity;
namespace DentistAppointmentSystem.AdminPages
{
    public partial class DPatients : System.Web.UI.Page
    {
        DentistAppointmentSystemEntities db = new DentistAppointmentSystemEntities();
        protected void Page_Load(object sender, EventArgs e)
        {
            var hastalar = (from x in db.TBL_PATIENTS
                            select new
                            {
                                x.TBL_USERS.Name,
                                x.TBL_USERS.Surname,
                                x.IDNumber,
                                x.Gender,
                                x.Birthday,
                                x.Phone
                            }).ToList();
            Repeater1.DataSource = hastalar;
            Repeater1.DataBind();

        }
    }
}

table

我使用实体框架从数据库中提取数据。但我想让性别数据为男性,如果为真,则为女性,如果为假

c# asp.net entity-framework
2个回答
0
投票

您可以在您的匿名投影中进行此更改。

var hastalar = (from x in db.TBL_PATIENTS
                            select new
                            {
                                x.TBL_USERS.Name,
                                x.TBL_USERS.Surname,
                                x.IDNumber,
                                Gender = x.Gender ? "Male" : "Female",
                                x.Birthday,
                                x.Phone
                            }).ToList();

0
投票

你也可以做一个功能:

    public string GetGender(bool gender)
    {
        if (gender)
        {
            return "Male";
        }
        else
        {
            return "Female";
        }
    }

然后这样称呼它:

x.Gender = GetGender(x.Gender)

© www.soinside.com 2019 - 2024. All rights reserved.