Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Using jQuery to get multiple checkbox's value and Multiple Delete Using jquery json

manoj1001289150manoj1001289150 indiaPosts: 1

I have already bind a html table using jQuery json. I want to get multiple checkbox value using jQuery json and delete by selected multiple delete method. This is my code for bind the table.
$(function () {
debugger
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebForm5.aspx/BindDatatable",
data: "{}",
dataType: "json",
success: function (dt) {
debugger;
for (var i = 0; i < dt.d.length; i++) {
$("#example1 > tbody").append("

" + dt.d[i].CategoryID + "" + dt.d[i].Name + "" + dt.d[i].Status + " SubmitDelete ");
             }
             $("#example1").DataTable();

         },
         error: function (result) {
             alert("Error");
         }
     });

 });

This is my Button to Delete selected(multiple delete):

Delete Selected

This is my html table:

<div class="box-body">
            <button type="button" name="deletebtn" id="deletebtn">Delete Selected</button>
          <table id="example1" class="table table-bordered table-striped">
            <thead>

              <tr>
                <th>Check Box</th>
                <th>Category Name</th>
                <th>Category Details</th>
                  <th>Status</th>
                  <th>Action</th>
              </tr>
            </thead>



              <tbody id="myBody">


              </tbody>

          </table>

        </div>

You just tell me :

1.what is the code to select all the checkbox??

2.Code to delete using multiple jquery??

The Server side Code is here For Single Delete(with out checkbox):

[WebMethod]
public static void deleteRecord(int Id)
{

    clsCategoryBL objproject = new clsCategoryBL();

    objproject.CategoryDelete(Id);

}

In BL:

public string CategoryDelete(int CategoryID)
{
using (KSoftEntities db = new KSoftEntities())
{
try
{

            var categoryDetails = db.tblCategories.Where(i => i.CategoryID == CategoryID).SingleOrDefault();
            db.tblCategories.Remove(categoryDetails);

            db.SaveChanges();
            return "Record deleted successfully";
        }
        catch (Exception ex)
        {

        }
        return "Error on deletion";
    }
}

The Delete is Occur on the Client Side by Using This code:

$().ready(function () {

     $('body').on('click', '#deletebtn', function () {
         debugger;
         $("#example1 tr").each(function () {
             var rowSelector = $(this);
             if (rowSelector.find("input[type='checkbox']").prop('checked')) {
                 rowSelector.remove();
             }

         });
     });
 });

I want To delete it on server Side that means also on my database(Sql) So what should i do???

I Want To Delete Multiple Row By Click On Multiple CheckBox On Database Also..I have mention in above the backend code also..I want to delete the row of html table by click 2 to 3 checkbox(it may be vary depend upon the data) and click Delete Selected button..

Tagged:
Sign In or Register to comment.