在asp.net中单击按钮获取td值,该按钮与angualrJS绑定

时间:2015-12-14 11:38:09

标签: javascript jquery angularjs

我有一个静态HTML表,其中2列1用于employeeID,其他用于Employee Name,关于每个条目,asp:按钮出现。我想点击按钮,它给了我employeeID。

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

下面是在表格中呈现值表单XML的脚本

var app = angular.module('myApp', []);
        app.controller('myCtrl', function ($scope, $http) {
            $http.get('myDB.xml')
            .then(function (response) {
                var x2js = new X2JS();
                //$scope.details = response.data.UserDetail;
                $scope.details = [];

                /*setting up the response*/
                var data = x2js.xml_str2json(response.data);
                $scope.details = data.UserDetail.Detail;
            });

        $scope.removerequest = function (row) {
            $scope.details.splice($scope.delete.indexOf(row), 1);
        }
    });

XML

<UserDetail>
  <Detail>
    <EmployeeID>997857</EmployeeID>
    <EmployeeName>Aakash</EmployeeName>
  </Detail>
  <Detail>
    <EmployeeID>999786</EmployeeID>
    <EmployeeName>Amit</EmployeeName>
  </Detail>
</UserDetail>

按钮点击代码

protected void btnDelete_Click(object sender, EventArgs e)
{
    string id=btnApprove.CommandArgument;
    Response.Write(id);
    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");
}

如何在命令参数形式中获取td值angularJS绑定元素

1 个答案:

答案 0 :(得分:0)

您可以在按钮中传递employeeIDng-click= btnDelete_Click( detail.EmployeeID )。这将获取由ng-repeat定义的范围变量,并将其作为函数BtnDelete_Click()

的参数传递