locked
Cancel event handler using webgrid in MVC asp net C# RRS feed

  • Question

  • User-1453200658 posted

    Hi,

    I have a problem when I try to cancel event handler using webgrid in MVC asp net C#.

    This is my code

    //Cancel event handler.
    $("body").on("click", "#WebGrid TBODY .Cancel", function () {
        var row = $(this).closest("tr");
        $("td", row).each(function () {
            if ($(this).find(".text").length > 0) {
                var span = $(this).find(".label2");
                var input = $(this).find(".text");
                input.val(span.html());
                span.show();
                input.hide();
            }
        });
        row.find(".Edit").show();
        row.find(".Update").hide();
        $(this).hide();
    });
    
    webGrid.Column(header: "day_gv",
    style: "day_gv",
    format: @<span>
    <span class="label2">@item.day_gv</span>@if (@item.Truefalse)
    {<span><input class="text" type="text" value="0000-00-00" style="display:none" disabled /></span>}
    else
    {<span><input class="text" type="text" value="@item.day_gv" style="display:none" /></span>}
    </span>)
    
    webGrid.Column(header: "day_hh",
    style: "day_hh",
    format: @<span>
    <span class="label2">@item.day_hh</span>@if (@item.Truefalse)
    {<span><input class="text" type="text" value="0000-00-00" style="display:none" disabled /></span>}
    else
    {<span><input class="text" type="text" value="@item.day_hh" style="display:none" /></span>}
    </span>)
    

    If editing the row where the value of @item.Truefalse is true

    enter image description here

    the return on webgrid is

    enter image description here

    If try cancel editing on the same row of @item.Truefalse is true and try to re-open EDIT, the return is empty

    enter image description here

    The problem it's if cancel editing and re-open EDIT on the same row , webgrid don't showing the values as the image number two inserted on this question and show empties input text on new editing as the image number three inserted on this question

    How to do resolve this?

    Sunday, May 30, 2021 3:59 PM

Answers

  • User-474980206 posted

    on cancel you set the input value to the label2 html (which appears to be blank).

    • Marked as answer by An0nym0u5User Tuesday, June 22, 2021 12:00 AM
    Monday, May 31, 2021 12:32 AM