Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3451770
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:10:53+00:00 2026-05-18T09:10:53+00:00

I am having a Gridview. I had placed a delete button in the last

  • 0

I am having a Gridview. I had placed a delete button in the last column of the row. whenever i click the delete button, the particular row should be deleted from the grid and also from the database.
Here is my aspx code

<script language="javascript" type="text/javascript">
    function DeleteEmployeeDetails(roleId) 
{
   if (confirm('Are you sure you want to delete this role?')) 
 {
 $.get("DeactivateRole?roleId=" + roleId,
 function () 
 {
     $('#row' + roleId).remove(); 
      //or
     $('#button' + roleId).parent().parent().remove(); 
 });
    }
}    function loadRoleList()
{
    $.ajaxSettings.cache = false;
    $.get(roleListActionUrl, roleList_callBack);
}

//This method is used to render the role details in the role List div
function roleList_callBack(data) {
    data = data + '<div id="AddRole"></div>';
    $("#EmpDetails").html(data);
}

This is my controller

 public ActionResult DeactivateRole(string roleId)
    {
       // What should i do here for Row Delete 
       return View();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:10:54+00:00Added an answer on May 18, 2026 at 9:10 am

    When I do something similar with AJAX I do two things:

    1. Delete in database
    2. Delete the row using javascript on callback e.g.

      function DeleteEmployeeDetails(roleId)
      {
      if (confirm(‘Are you sure you want to delete this role?’)) {
      $.get(“DeactivateRole?roleId=” + roleId, function() {

             //roleList_callBack();
      
      
      
         $('#row' + roleId).remove(); //Grab the row and delete it
      
      
         //If you don't have specific Id's for every row but your button does you could use the $.parent() function.
      
      
         $('#button'+roleId).parent().parent().remove(); //This finds the parent of the parent of the button and removes it. You can use as many parents as you'd like until you get a hold on the actual row, though this isn't always recommended due to if you change the design in some way your parent might not be correct. 
      
      
      });
      

      }

      }

    If the delete succeeds in your database the row disappears instantly and you don’t have to reload all the data from the database.

    How you delete a row in your database depends on which framework you use. If you use ADO.NET Entity Framework you could do something like this:

    public ActionResult DeactivateRole(string roleId)
    {

       My_Namespace.Models.DataContext dc = new My_Namespace.Models.DataContext();
    
       dc.DeleteObject(dc.Roles.FirstOrDefault(r => r.ID == roleId)); 
       dc.SaveChanges();
    
       return View();
    }
    

    The DeleteObject() method takes an actual database-entity-object as argument which it uses to delete the corresponding entry in you database.

    The argument I use(dc.Roles.FirstOrDefault(r => r.ID == roleId)) gets the object from the database Roles-table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble getting the following code to work: $('#changeMode').button().click(function(){ $('#playfield').toggle(function() { $(this).switchClass(gridView,plainView); }, function()
I have a asp gridview with button field column on that button click I
I am having a gridview which consist of add button for adding a new
I'm having some trouble getting a GridView column of strings to sort properly. The
I'm having some trouble with editing a gridview row's background color when Editing it.
I am having a gridview with some columns and a template field column that
Hi I am trying Export data to excel sheet from GridView but having this
I've been having troubles getting my textbox to refresh a GridView from the onchange
I am having editable Gridview with column named Country which has so long listing.
Hi all i am having 2 imagebuttons a gridview and a button. Now if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.