skip to Main Content

I try to make patients table. I pulled the data from the database with entityframework. But I want to make the gender data male if true then female if false

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

I pulled the data from the database with entityframework. But I want to make the gender data male if true then female if false

2

Answers


  1. You can make this change within your anonymous projection.

    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();
    
    Login or Signup to reply.
  2. You can also make a function :

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

    and then call it like:

    x.Gender = GetGender(x.Gender)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search