显示数据库中的Checkbox Tick for 1 [英] displaying Checkbox Tick for 1 from database
本文介绍了显示数据库中的Checkbox Tick for 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将CHECKBOX与SQL Bit字段绑定,其中包含1,0,Null所以我想显示我的复选框,TICK为1,Empty为0.
使用MVC 3,LINQ TO SQL,c#
代码:
@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 =lblApprovedclass =editEmp_label >加班批准< / label>
< input type =CheckBoxname =Approvalvalue =@Item.OvertimeApproved />
< br />
}
控制器:
public ActionResult EditEmployee()
{
if(!String.IsNullOrEmpty(Session [Admin] as string))
{
诠释? EmplId = Convert.ToInt32(Session [EmpEdit]);
IEnumerable< GetEmployeeEditDetails_SpResult> EmployeeValues = DataContext.GetEmployeeEditDetails_Sp(EmplId).ToList();
var DepNames =(来自DataContext.HrDepts中的n选择new {n.DeptID,n.DeptName})。Distinct();
ViewData [DeptID] =新的SelectList(DepNames,DeptID,DeptName);
var ShiftNames =(来自DataContext.AtdShifts中的n选择新的{n.ShiftId,n.ShiftName})。Distinct();
ViewData [ShiftId] =新的SelectList(ShiftNames,ShiftId,ShiftName,新选择);
return View(EmployeeValues);
}
解决方案
< asp:TemplateField HeaderText = SinglePayment < span class =code-keyword>>
< ItemTemplate >
< asp:CheckBox ID = chkDis TabIndex = 6 runat = server
< span class =code-attribute> < span class =code-attribute> 已检查 =' < span class =code-pagedirective><% #Eval( SinglePayMent ).ToString()。Equals( 1,StringComparison.OrdinalIgnoreCase)%> ' / >
< / ItemTemplate >
< / asp:TemplateField >
@ Html.CheckBox(Approval, @ Convert.ToBoolean(@ Item.OvertimeApproved))
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); }解决方案<asp:TemplateField HeaderText = "SinglePayment"> <ItemTemplate> <asp:CheckBox ID="chkDis" TabIndex="6" runat="server" Checked='<%# Eval("SinglePayMent").ToString().Equals("1", StringComparison.OrdinalIgnoreCase) %>' /> </ItemTemplate> </asp:TemplateField>
@Html.CheckBox("Approval", @Convert.ToBoolean( @Item.OvertimeApproved))
这篇关于显示数据库中的Checkbox Tick for 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文