在webgrid上重复验证

时间:2019-05-22 07:07:36

标签: c# jquery .net webgrid

我有一个网格,在上面可以从前端添加行,并使用以下代码可以正常工作,但是现在我必须在插入之前为重复的行添加一个验证(即,我不想添加重复的行) :

$("#Submit_AddRow1").click(function () {
if (($('#txtPracticeArea').val() == '') && ($('#txtMarketArea').val() == '')) {
    alert('Atleast One Value is mandatory!');
}
else {
    //Reference the WebGrid.
    var webGrid = $("#GridPractice");

    //Reference the first row.
    var row = webGrid.find("tr").eq(1);

    //Check if row is dummy, if yes then remove.
    if (($.trim(row.find("td:eq(0)").html()) == "") &&         ($.trim(row.find("td:eq(1)").html()) == "")) {
        row.remove();
    }

    //Clone the reference first row.
    row = row.clone(true);

    //Reference the Practice Area TextBox.
    var txtPracticeArea = $("#txtPracticeArea");

    //Reference the Market Area TextBox.
    var txtMarketArea = $("#txtMarketArea");

    //Add the Practice Area value to first cell.
    SetValue(row, 0, txtPracticeArea);

    //Add the Market Area value to second cell.
    SetValue(row, 1, txtMarketArea);

    //Add the row to the WebGrid.
    webGrid.append(row);

    webGrid.show();

    $('#gridPractice').show();
    }
});

这是我的网格

new { @id = "GridPractice", @class = "table table-sm     
table-striped table-bordered table-condensed", @style = "width:100%" },
    columns: grid1.Columns(
    grid1.Column("PracticeArea", "Practice Area"),
    grid1.Column("MarketArea", "Market Area"),
    grid1.Column(format: @<text>
    <a data-title="Are you sure to deactivate this Input?"     
onclick="DeleteRow()"><i class="fa fa-trash" style="color:red"></i></a>    
</text>, header: "Remove")));

0 个答案:

没有答案