Solved

How to delete checked records in gridview.

Posted on 2009-03-30
2
265 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
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

830 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