ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Checkboxes in Grid
Title:
B
I
{code}
?
I am attempting to show 3 different checkbox fields in a Grid with inline editing. The checkbox value comes from the database based on 1 or 0's, not true or false. The code I currently have in place works for the display, but when I go to edit they all say "No", even though they have 1's for their corresponding values and the disp value shows up as "x". How can I get the grid to understand we are working with 1's and 0's? The GetItems Display code (DispEnabled1, DispEnabled2, DispEnabled3) works fine, just having trouble with inline editing and the actual fields (Enabled1,Enabled2,Enabled3) Here is my code: @{ var gridId = "TCMan"; } <div class="bar"> <div style="float:left;"> <button type="button" onclick="$('#TCMan').data('api').inlineCreate()" class="awe-btn mbtn">Create</button> </div> </div> @Html.InitDeletePopupForGrid(gridId, "TCMan") @(Html.Awe().Grid(gridId) .Mod(o => o.PageInfo().InlineEdit(Url.Action("Create", "TCMan"), Url.Action("Edit", "TCMan"))) .Url(Url.Action("GetItems", "TCMan")) .Groupable(false) .PageSize(100) .Columns( new Column { ClientFormat = GridUtils.InlineEditFormat(), Width = 70 }, new Column { Bind = "id", Hidden = true } .Mod(o => o.InlineId()), new Column { Bind = "Name" } .Mod(o => o.Inline(Html.Awe().TextBox("Name"))), new Column { Bind = "Number", Hidden = true, SortRank = 1, Sort = Omu.AwesomeMvc.Sort.Asc } .Mod(o => o.Inline(Html.Awe().TextBox("Number"))), new Column { Bind = "Enabled1", Width = 100, ClientFormat = ".DispEnabled1" } .Mod(o => o.Inline(Html.Awe().CheckBox("Enabled1").Otoggl())), new Column { Bind = "Enabled2", Width = 100, ClientFormat = ".DispEnabled2" } .Mod(o => o.Inline(Html.Awe().CheckBox("Enabled2").Otoggl())), new Column { Bind = "Enabled3", Width = 100, ClientFormat = ".DispEnabled3" } .Mod(o => o.Inline(Html.Awe().CheckBox("Enabled3").Otoggl())), new Column { ClientFormat = Html.InlineDeleteFormatForGrid(gridId), Width = 80 })) And here is my GetItems (the DispEnabled1-3 work upon GridLoad, I have the conditional code for each DispEnabled1-3) private object MapToGridModel(TCMan o) { return new { o.id, o.Name, o.RequestID, o.Number, o.Enabled1, DispEnabled1 = (o.Enabled1 == 1) ? "X" : "", o.Enabled2, DispEnabled2 = (o.Enabled2 == 1) ? "X" : "", o.Enabled3, DispEnabled3 = (o.Enabled3 == 1) ? "X" : "" }; } public ActionResult GetItems(GridParams g) { var list = db.TCMen.AsQueryable(); return Json(new GridModelBuilder<TCMan>(list, g) { Key = "id", GetItem = () => db.TCMen.Find(Convert.ToInt32(g.Key)), Map = MapToGridModel }.Build()); }
Save Changes
Cancel
eliawesome
asked at 30 Oct 2018
Answers
B
I
{code}
?
The awesome checkbox needs the value `true` to check the checkbox. You're storing the boolean value in the database as 1 and 0, that doesn't mean that you have to have it in the UI as 1 and 0 as well, one solution would be: private object MapToGridModel(TCMan o) { return new { ... Enabled1 = o.Enabled1 == 1 ? true : false, DispEnabled1 = (o.Enabled1 == 1) ? "X" : "", Enabled2 = o.Enabled2 == 1 ? true : false, ... etc. }; } In the Edit/Create post action the viewmodel also needs to be changed to be have bool types for the Enabled properties
Save Changes
Cancel
Omu
answered at 30 Oct 2018
I figured out my issue. Thanks for the help again.
at 01 Nov 2018
eliawesome
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK