Solved

How to delete checked records in gridview.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now