Solved

How to delete checked records in gridview.

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

776 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