Advertisement
Guest User

Untitled

a guest
Feb 26th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. <head runat="server">
  2. <title></title>
  3.  
  4. <script src="Scripts/angular.min.js"></script>
  5.  
  6. <script>
  7.  
  8. var app = angular.module("myModule", []).controller("myController",
  9. function($scope, $http) {
  10.  
  11. $http.get("UsersService.asmx/GetAllUsers").then(function(response) {
  12.  
  13. $scope.users = response.data;
  14.  
  15. });
  16. });
  17.  
  18. </script>
  19.  
  20. </head>
  21. <body ng-app="myModule">
  22. <form id="form1" runat="server">
  23. <div ng-controller="myController">
  24.  
  25. <table>
  26. <thead>
  27. <tr>
  28. <th>ID</th>
  29. <th>Username</th>
  30. <th>Password</th>
  31. <th>LastLogin</th>
  32. </tr>
  33. </thead>
  34. <tbody>
  35. <tr ng-repeat="user in users">
  36. <td>{{ user.ID }}</td>
  37. <td>{{ user.Username }}</td>
  38. <td>{{ user.Password }}</td>
  39. <td>{{ user.LastLogin }}</td>
  40. </tr>
  41. </tbody>
  42. </table>
  43.  
  44. </div>
  45. </form>
  46. </body>
  47. </html>
  48.  
  49. [WebMethod]
  50. public void GetAllUsers()
  51. {
  52. List<User> listUsers = new List<User>();
  53. string cs = ConfigurationManager.ConnectionStrings["AngularJS_ConnectionString"].ConnectionString;
  54. using (SqlConnection con = new SqlConnection(cs))
  55. using (SqlCommand cmd = new SqlCommand("SELECT * FROM Users", con))
  56. {
  57. con.Open();
  58. using (SqlDataReader sdr = cmd.ExecuteReader())
  59. {
  60. while (sdr.Read())
  61. {
  62. User user = new User();
  63. user.ID = Convert.ToInt32(sdr["UserID"]);
  64. user.Username = sdr["Username"].ToString();
  65. user.Password = sdr["Password"].ToString();
  66. user.LastLogin = sdr["LastLogin"] as DateTime?;
  67. listUsers.Add(user);
  68. }
  69. }
  70. }
  71.  
  72. JavaScriptSerializer js = new JavaScriptSerializer();
  73. Context.Response.Write(js.Serialize(listUsers));
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement