Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('#deleteStudent').click(function () {
- var dataArr = [];
- $.each($("#StudentTable tr.selected"), function () {
- dataArr.push($(this).find('td').eq(0).text());
- });
- var StudentList = JSON.stringify(dataArr);
- $.ajax({
- type: "POST",
- url: "ViewStudents.aspx/DeleteStudent",
- contentType: "application/json; charset=utf-8",
- data: { Students: dataArr },
- dataType: "json",
- traditional: true,
- success: function (result) {
- alert('Yay! It worked!');
- },
- error: function (result) {
- alert('Oh no :( : '+result);
- }
- });
- console.log(StudentList);
- });
- ["10363","10364","10366"]
- [WebMethod]
- public static void DeleteStudent(string[] Students)
- {
- Console.WriteLine("Reached CS");
- string[] a =Students;
- for (int i = 0; i < a.Length; i++)
- {
- string admissionNumber=a[i];
- using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString))
- {
- using (MySqlCommand deleteStudent = new MySqlCommand())
- {
- deleteStudent.CommandType = CommandType.Text;
- deleteStudent.Connection = conn;
- deleteStudent.CommandText = "DELETE FROM validstudents WHERE admissionNumber = @admissionNumber ";
- deleteStudent.Parameters.AddWithValue("@admissionNumber", admissionNumber);
- conn.Open();
- deleteStudent.ExecuteNonQuery();
- conn.Close();
- }
- }
- }
- }
- data: JSON.stringify({ Students: dataArr })
- var optionSelected ="me"
- var id = { id: optionSelected };
- $.ajax({
- url: '@Url.Action("GetConnectionProvider", "Customers")',
- contentType: "application/json;charset=utf-8",
- data: JSON.stringify(id),
- type: 'POST',
- dataType: 'json',
- success: function(datas) {
- }
- });
- In Action
- public ActionResult GetConnectionProvider(int id)
- {
- //write your code
- }
- [WebMethod]
- public static void DeleteStudent(string[] data)
- {
- [WebMethod]
- public static void DeleteStudent(List<string> data)
- {
- data: { data : dataArr },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement