Hi I want to delete record form XML file on the click of asp.net button. But is generated on runtime from AngularJS

Below is my XML file which I use to display data in table format

<UserDetail>
  <Detail>
    <EmployeeID>124578</EmployeeID>
    <EmployeeName>suresh</EmployeeName>
    <EmailID>suresh@xyz.com</EmailID>
  </Detail>
  <Detail>
    <EmployeeID>587458</EmployeeID>
    <EmployeeName>Vivek</EmployeeName>
    <EmailID>vjain@xyz.com</EmailID>
  </Detail>
</UserDetail>

Here is my HTML code with that my data coming in table format

<div ng-app="myApp" ng-controller="myCtrl">
            <table border="1" width="100%">
                <tr>
                    <th>Employee ID</th>
                    <th>Employee Name</th>
                    <th>Email ID</th>
                    <th>Status</th>
                </tr>
                <tr ng-repeat="detail in details" align="center">
                    <td>{{detail.EmployeeID}}</td>
                    <td>{{detail.EmployeeName}}</td>
                    <td>{{detail.EmailID}}</td>
                    <td>
                        <asp:Button CssClass="btnDelete" Text="Delete Record" runat="server" ng-click="getID(detail.EmployeeID)" OnClick="btnDelete_Click"/>
                    </td>
                </tr>
            </table>
        </div>

Here is my AngularJS code with that I m get changing XML to JSON and present in the form of table

<script>
        var app = angular.module('myApp', []);
        app.controller('myCtrl', function ($scope, $http) {
            $http.get('myDB.xml')
            .then(function (response) {
                var x2js = new X2JS();
                $scope.details = [];
                var data = x2js.xml_str2json(response.data);
                $scope.details = data.UserDetail.Detail;
                $scope.getID = function (id) {                 
                    if (this == id)
                    {
                        $scope.UserDetail.Detail.splice(index, 1);
                    }
                }
            });

        });
      </script>

My Delete Record button code

protected void btnDelete_Click(object sender, EventArgs e)
{
    var xDoc = XDocument.Load(@"D:\test\myDB.xml");
    xDoc.Descendants("Detail")
       .Elements("EmployeeID")
       .Where(x => x.Value == id)
       .Remove();
    xDoc.Save(@"D:\test\myDB.xml");
}

Help me to delete record from XML file

Related posts

Recent Viewed