Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am trying to bind CHECKBOX with SQL Bit field which contains 1, 0, Null so i want to display my checkbox with TICK for 1 and Empty for 0.
Using MVC 3, LINQ TO SQL, c#

Code:

@using EmployeeAttendance_app.Models
@model IEnumerable<GetEmployeeEditDetails_SpResult>
          
@{
    var Item = Model.FirstOrDefault();
 }
           
<style type="text/css">

</style>
<div>
@using (Html.BeginForm("EditEmployee", "Home", FormMethod.Get))
{
  
  <label id="lblApproved" class="editEmp_label">Overtime Approval</label>
  <input type="CheckBox"  name="Approval" value=@Item.OvertimeApproved />
  <br />
  
  
}


Controller:

public ActionResult EditEmployee()
       {
           if (!String.IsNullOrEmpty(Session["Admin"] as string))
           {
               int? EmplId = Convert.ToInt32(Session["EmpEdit"]);
               IEnumerable<GetEmployeeEditDetails_SpResult> EmployeeValues = DataContext.GetEmployeeEditDetails_Sp(EmplId).ToList();
               var DepNames = (from n in DataContext.HrDepts select new { n.DeptID, n.DeptName }).Distinct();
               ViewData["DeptID"] = new SelectList(DepNames, "DeptID", "DeptName");
               var ShiftNames = (from n in DataContext.AtdShifts select new { n.ShiftId, n.ShiftName }).Distinct();
               ViewData["ShiftId"] = new SelectList(ShiftNames, "ShiftId", "ShiftName", new select);
               return View(EmployeeValues);
           }
Posted

XML
<asp:TemplateField HeaderText = "SinglePayment">
                                                               <ItemTemplate>
                                                                   <asp:CheckBox ID="chkDis"  TabIndex="6" runat="server"
                                                                    Checked='<%# Eval("SinglePayMent").ToString().Equals("1", StringComparison.OrdinalIgnoreCase) %>' />
                                                               </ItemTemplate>
                                                                                                          </asp:TemplateField>
 
Share this answer
 
@Html.CheckBox("Approval", @Convert.ToBoolean( @Item.OvertimeApproved))
 
Share this answer
 
Comments
Member 10517120 26-Feb-14 6:01am    
yes exactly

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