Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
PROBLEM-now prob is when i click on edit button each time it will show the old value also with the new one in listbox. so how can i unselect old item from listbox.
and one more thing if want to select one more item to update record from listbox how can i do that...

What I have tried:

my view:

HTML
<div class="row">
 
    <div class="col-lg-6">

       @using (Html.BeginForm("ModuleMapping", "Setup", FormMethod.Post, new { @class = "form-horizontal"}))
        { 
    <div class="form-group">
                @Html.Label("Employee", new { @class = "control-label col-lg-4" })               
                <div class="col-lg-8">               
                 @Html.DropDownListFor(model => model.EmployeeId, new MultiSelectList(@Model.employeeList, "Id", "EmpDisplayName"), "Select Employee", new { @class = "form-control" })
               </div>
                @Html.ValidationMessageFor(m => m.EmployeeId)
            </div> 
            <div class="form-group">
                @Html.Label("Module Name", new { @class = "control-label col-lg-4" })               
                <div class="col-lg-8"> 
                @Html.ListBox("Module", new SelectList(@Model.moduleList, "Id", "Name"), new { @class = "text form-control" })
               </div>
                @Html.ValidationMessageFor(m => m.EmployeeId)
                </div>           
         <div class="col-lg-8">
                <input type="submit" id="Add" value="Add" name="Command" class="btn btn-metis-6 btn-sm" />
                 <input type="submit" id="Update" value="Update" name="Command" class="btn btn-metis-6 btn-sm" style="display:none" />
                 <input type="button" id="Reset" value="Reset" class="btn btn-metis-6 btn-sm" style="display:none" onclick="return reset();" />
                  
            </div>
   
        }


    </div></div></div>
<div class="row">
 
<table id="dataTable" class="table table-bordered table-condensed table-hover table-striped">
    <thead>
<tr>
<th>Employee</th>
<th>Module</th>
<th>Action</th>
</tr>
        </thead>
    <tbody>
        @if (Model.moduleMappedList.Count > 0)
{
    foreach (var item in Model.moduleMappedList)
    {
        <tr>
          <td>
            @item.EmployeeName
            </td>
            <td>
            @foreach (var module in item.ModuleMapList)
            {
                    @Html.DisplayFor(modelItem => module.ModuleName)<br />
            }
            </td>     
            <td>           
             <a href="#" class="btn btn-metis-5 btn-lg" data-original-title="" title="" onclick="return SelectModuleMapping(@item.EmployeeId)"><i class="glyphicon glyphicon-edit"></i></a>
            </td>
        
        </tr>
    }
}
        </tbody>

</table>

</div>
             <script src="/MobileApp/Scripts/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function () {
        $('#dataTable').dataTable(
      {
          "sDom": '<"toolbar">frtip',
          "iDisplayLength": 25
      });
    });
    function SelectModuleMapping(id) {
        debugger;
        if (id != null) {
            $.ajax({
                type: "POST",
                url: "/MobileApp/Setup/GetModuleMapping",
                data: "{'id':" + id + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: SelectModuleMappingSuccess,
                error: SelectModuleMappingFail
            });
        }
    }
    function SelectModuleMappingSuccess(result) {
        debugger;
        //for (var i = 0; i < result.length; i++) {
        //    var list = document.getElementById("Module");
        //    list.options[result[i].ModuleId - 1].selected = false;
        //}
        var list = document.getElementById("Module");
        if (list.SelectedItem > -1)
        {
            var s = list.SelectedItem.Value;
          
            list.Items.Remove(s);
        }  
        for (var i = 0; i < result.length; i++) {
            var list = document.getElementById("Module");
            list.options[result[i].ModuleId - 1].selected = true;
            document.getElementById("EmployeeId").value = result[i].EmployeeId;
        }
        $("#Add").hide();
        $("#Update").show();
        $("#Reset").show();
    }
    function SelectModuleMappingFail() {
    }
    $('#Reset').click(function () {
        document.location = '@Url.Action("ModuleMapping","Setup")';
    });
</script>
Posted

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