Solved

How to delete checked records in gridview.

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

20 Experts available now in Live!

Get 1:1 Help Now