Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. $('#deleteStudent').click(function () {
  2. var dataArr = [];
  3. $.each($("#StudentTable tr.selected"), function () {
  4. dataArr.push($(this).find('td').eq(0).text());
  5. });
  6. var StudentList = JSON.stringify(dataArr);
  7. $.ajax({
  8. type: "POST",
  9. url: "ViewStudents.aspx/DeleteStudent",
  10. contentType: "application/json; charset=utf-8",
  11. data: { Students: dataArr },
  12. dataType: "json",
  13. traditional: true,
  14. success: function (result) {
  15. alert('Yay! It worked!');
  16. },
  17. error: function (result) {
  18. alert('Oh no :( : '+result);
  19. }
  20. });
  21. console.log(StudentList);
  22. });
  23.  
  24. ["10363","10364","10366"]
  25.  
  26. [WebMethod]
  27. public static void DeleteStudent(string[] Students)
  28. {
  29. Console.WriteLine("Reached CS");
  30. string[] a =Students;
  31. for (int i = 0; i < a.Length; i++)
  32. {
  33. string admissionNumber=a[i];
  34. using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString))
  35. {
  36. using (MySqlCommand deleteStudent = new MySqlCommand())
  37. {
  38. deleteStudent.CommandType = CommandType.Text;
  39. deleteStudent.Connection = conn;
  40. deleteStudent.CommandText = "DELETE FROM validstudents WHERE admissionNumber = @admissionNumber ";
  41.  
  42. deleteStudent.Parameters.AddWithValue("@admissionNumber", admissionNumber);
  43.  
  44. conn.Open();
  45. deleteStudent.ExecuteNonQuery();
  46. conn.Close();
  47. }
  48. }
  49. }
  50. }
  51.  
  52. data: JSON.stringify({ Students: dataArr })
  53.  
  54. var optionSelected ="me"
  55. var id = { id: optionSelected };
  56.  
  57. $.ajax({
  58. url: '@Url.Action("GetConnectionProvider", "Customers")',
  59. contentType: "application/json;charset=utf-8",
  60. data: JSON.stringify(id),
  61. type: 'POST',
  62. dataType: 'json',
  63. success: function(datas) {
  64.  
  65.  
  66. }
  67. });
  68. In Action
  69.  
  70. public ActionResult GetConnectionProvider(int id)
  71. {
  72. //write your code
  73. }
  74.  
  75. [WebMethod]
  76. public static void DeleteStudent(string[] data)
  77. {
  78.  
  79. [WebMethod]
  80. public static void DeleteStudent(List<string> data)
  81. {
  82.  
  83. data: { data : dataArr },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement