Click here to Skip to main content
12,884,793 members (31,297 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
Dear Friends,

Am working on C# , , SqlServer 2005.

I have a gridview with data filled in it.

am using Header and row by row checkboxes to delete single and multiple records.

this is my design page.

                    <asp:CheckBox ID="Checkall" runat="server"  onclick="javascript:SelectAll(this);" />
                    <asp:CheckBox ID="Chkselect" runat="server" />
                <asp:BoundField DataField="UserName" HeaderText="UserName"
                    SortExpression="UserName" />
                <asp:BoundField DataField="Login_Time" HeaderText="Login_Time"
                    SortExpression="Login_Time" />
                <asp:BoundField DataField="Logout_Time" HeaderText="Logout_Time"
                    SortExpression="Logout_Time" />

Please can anybody help me, how to delete the records by selecting checkboxes

I need All records to be deleted and multiple deletion, and single deletion.

Please help me

Posted 12-Jun-12 1:08am
RDBurmon 13-Jun-12 9:34am
Thanks Everyone who replied to this thread , So Ranjith, I think you have got enough responses and you should be able to mark it as your answer and close the thread. Please do so.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Vani Kulkarni 12-Jun-12 7:11am
Good Link!
Prasad_Kulkarni 12-Jun-12 7:36am
Thank you Vani!
VJ Reddy 12-Jun-12 11:18am
Good references. 5!
Prasad_Kulkarni 12-Jun-12 23:46pm
Thank you VJ!
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Add Grid View Like this

<asp:GridView ID="GVID">
<asp:TemplateField HeaderText="Select">
                                                                                                       <asp:CheckBox ID="QchkBxSelect" runat="server" />
                                                                                                       <asp:CheckBox ID="QchkBxHeader" onclick="javascript:QHeaderClick(this);" runat="server" />
<asp:TemplateField HeaderText="Risk ID" meta:resourcekey="asptempriskid">
                                                                                                       <asp:Label ID="lbluniqueId" Text='<%# Eval("uniqueID") %>' runat="server"></asp:Label>

Call The Java Script to Select DeSelect Checkbox

<script type="text/javascript">
var QTotalChkBx;
        var QCounter;

        window.onload = function () {
            //Get total no. of CheckBoxes in side the GridView.
            QTotalChkBx = parseInt('<%= this.GVID.Rows.Count %>');
            //Get total no. of checked CheckBoxes in side the GridView.
            QCounter = 0;
function QHeaderClick(QCheckBox) {
            //Get target base & child control.
            var QTargetBaseControl =
       document.getElementById('<%= this.GVID.ClientID %>');
            var QTargetChildControl = "QchkBxSelect";
            //Get all the control of the type INPUT in the base control.
            var QInputs = QTargetBaseControl.getElementsByTagName("input");
            //Checked/Unchecked all the checkBoxes in side the GridView.
            for (var n = 0; n < QInputs.length; ++n)
                if (QInputs[n].type == 'checkbox' &&
                QInputs[n].id.indexOf(QTargetChildControl, 0) >= 0)
                    QInputs[n].checked = QCheckBox.checked;
            //Reset Counter
            QCounter = QCheckBox.checked ? QTotalChkBx : 0;
        function QChildClick(QCheckBox, QHCheckBox) {
            //get target control.
            var QHeaderCheckBox = document.getElementById(QHCheckBox);
            //Modifiy Counter;
            if (QCheckBox.checked && QCounter < QTotalChkBx)
            else if (QCounter > 0)
            //Change state of the header CheckBox.
            if (QCounter < QTotalChkBx)
                QHeaderCheckBox.checked = false;
            else if (QCounter == QTotalChkBx)
                QHeaderCheckBox.checked = true;


add Asp Button Outside Grid View Like this
<asp:Button ID="Delete" runat="server" Text="Delete "
                                                                                            OnClick="Delete_Click" />

Try this below Code In Delete Button onClick Event

string flagchecked = "0";
ArrayList arrrid = new ArrayList();
// Select the checkboxes from the GridView control
for (int i = 0; i < GVID.Rows.Count; i++)
GridViewRow row = GVID.Rows[i];
bool isChecked = ((CheckBox)row.FindControl("chkBxSelect")).Checked;

if (isChecked)
flagchecked = "1";
string uniqueid= ((Label)row.FindControl("lblitemuniqueId")).Text;
if (flagchecked == "1")
for (int jR = 0; jR < arrrid.Count; jR++)
//Delete Operation

Rate this: bad
Please Sign up or sign in to vote.

Solution 4


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 12 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100