Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am picking BIT field from SQL server ISApproved field which stores 0 , 1 but when i pick it in my C# then it shows TRUE FALSE in column but i want YES NO instead of it.

C#
CODE:

public ActionResult ShowHrEmployeeRec(int? EmplID = null)
        {
            if (!String.IsNullOrEmpty(Session["Admin"] as string))
            {

                IEnumerable<GetHrEmployeeResult> HrEmployee = DataContext.GetHrEmployee(EmplID).ToList();
                ViewBag.Month = Request.QueryString["Month"];
                return View(HrEmployee);
            }
            else
            {
                return RedirectToAction("IsAuth_Page", "Home");
            }
VIEW:

 @{
 
     var grid = new WebGrid(ViewData.Model, defaultSort: "EmplID", rowsPerPage: 1);
    
  }

  @if (Model.Count > 0)
  {
      <div id="AllEmpGrid_ByName">
       @grid.GetHtml(columns: grid.Columns(
                                            grid.Column("EmplID", "Employee ID"),
                                            grid.Column("EmplName", "Employee Name"),
                                            grid.Column("DeptName", "Department"),
                                            grid.Column("ShiftName", "Shift"),
                                            grid.Column("EntryDate", "Entry Date"),
                                            grid.Column("BasicSalary", "Basic Salary"),
                                            grid.Column("EmailAdd", "Email"),
                                            grid.Column("OvertimeApproved", "Overtime Approval")
                                           ))
     </div>
  }
Posted
Updated 22-Dec-16 15:43pm

The easiest way to do this is on the database side.
SQL
SELECT IIF(IsApproved, "YES", "NO") AS OvertimeApproved
 
Share this answer
 
Comments
Maarten Kools 25-Feb-14 5:42am    
+5 Much cleaner than my solution. My SQL is a bit rusty :|
thatraja 25-Feb-14 5:52am    
5! I'm sure you're a VB programmer :D
[no name] 25-Feb-14 6:45am    
Yes, I was :-)
Maciej Los 25-Feb-14 6:04am    
+5
_Zorro_ 25-Feb-14 8:26am    
You should never manipulate data on the dbms. That kind of transformations should be done on the entity itself or the business layer.
Use the CASE[^] statement in your SQL query.

e.g.
C#
select col1, col2 = case when IsApproved != 0 then "yes" else "no" end, col 3 from mytable
 
Share this answer
 
Comments
thatraja 25-Feb-14 5:54am    
Still 5!
Maarten Kools 25-Feb-14 6:06am    
Thank you. You and Maciej.Los are too kind :)
Maciej Los 25-Feb-14 6:04am    
+5
you can do it in MVC WEB GRID like this.

C#
grid.Column("OvertimeApproved", header: "Overtime Approval",
                     format:
                    @<text> 
                            @if(item.IsApproved)
                            {
                                <span>Yes</span>
                            }
                            else
                            {
                                <span>No</span>
                            }
                    </text>
                    )
 
Share this answer
 
We can use the case statement to achieve it

select case when IsAdmin=1 then 'Yes' else 'NO' end from Tablename
 
Share this answer
 
Comments
Maciej Los 23-Dec-16 1:54am    
Is there any reason to post the same answer as solution #2?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900