Solved

How to delete checked records in gridview.

Posted on 2009-03-30
2
267 Views
Last Modified: 2012-05-06
I have a gridview with checkboxes.How to delete checked records by clicking on the delete button.(Can any one provide javascript for this.)
Note:Delete button is outside of gridview.
0
Comment
Question by:UJayaPrakashRao
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 31

Accepted Solution

by:
RiteshShah earned 500 total points
ID: 24017262
you can't delete records from javascript, if you are fetching records from your serverside SQL Server. however, you can use below given server side code on your button's click event.
 protected void btnDelete_Click(object sender, EventArgs e)
    {
        string strID = "";
        //check box object
        CheckBox chk = new CheckBox();
        //grid view name is  dgProcesseddata, iterating till all records check
        for (int i = 0; i < dgProcesseddata.Rows.Count; i++)
        {
            //first column is checkbox column
            //so checking whether it is checked or not
            chk = (CheckBox)(dgProcesseddata.Rows[i].FindControl("chkCheck"));
            if (chk.Checked == true)
            {
                //if checkbox is checked than finding "lblID" which has primary key value
                strID = ((Label)(dgProcesseddata.Rows[i].FindControl("lblID"))).Text;
                //pass primary key to DeleteRecordFromParent function which will delete records
                //based on primary key
                DeleteRecordFromParent(strID);
            }
        }
        //rebind the gridview
        BindataToGrid();
 
    }

Open in new window

0

Featured Post

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question