Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 6th, 2007, 02:49 AM
Registered User
Join Date: Apr 2006
Location: new delhi, new delhi, India.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deepakbachelor
Default Deleting multiple rows in data view or grid

<script language="javascript" type="text/javascript">
    function select_deselectAll (chkVal, idVal)
    var frm = document.forms[0];
    // Loop through all elements
    for (i=0; i<frm.length; i++)
        // Look for our Header Template's Checkbox
        if (idVal.indexOf ('CheckAll') != -1)
            // Check if main checkbox is checked, then select or deselect datagrid checkboxes
            if(chkVal == true)
                frm.elements[i].checked = true;
                frm.elements[i].checked = false;
            // Work here with the Item Template's multiple checkboxes
        else if (idVal.indexOf ('DeleteThis') != -1)
            // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
            if(frm.elements[i].checked == false)
                frm.elements[1].checked = false; //Uncheck main select all checkbox

function confirmDelete (frm)
    // loop through all elements
    for (i=0; i<frm.length; i++)
        // Look for our checkboxes only
        if (frm.elements[i].name.indexOf("DeleteThis") !=-1)
            // If any are checked then confirm alert, otherwise nothing happens
                return confirm ('Are you sure you want to delete your selection(s)?')
<asp:GridView ID="DgAddress" runat="server" PageSize="40" Width="278px" AutoGenerateColumns="False">
            <PagerStyle BackColor="#C000C0" />
            <AlternatingRowStyle BackColor="#C0C0FF" BorderColor="#C0C0FF" BorderStyle="Solid"
                ForeColor="#8080FF" />
                <asp:Button ID="BtnGrid" runat="server" Text="Delete"/>
                <asp:BoundField HeaderText="ID" DataField="Id" Visible="false" />
                <asp:BoundField HeaderText="Employee Id" DataField="EmpId"/>
                <asp:BoundField HeaderText="Employee Name" DataField="EmpName"/>
                <asp:CommandField InsertText="Delete" ShowDeleteButton="True"/>
                <asp:CheckBox Id="CheckAll" onClick="javascript: return select_deselectAll (this.checked, this.id);" runat=server/>
                <asp:HiddenField ID="chkid" runat="server" Value=<%#Container.DataItem("Id")%>/>
                <asp:CheckBox Id="DeleteThis" onClick="javascript: return select_deselectAll (this.checked, this.id);" runat=server/>

<asp:Button Text="Delete Items" ID="Confirm" runat="server" />

Protected Sub Confirm_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Confirm.Click
        Dim dgIDs As String = ""
        Dim BxsChkd As Boolean
        Dim i As Integer
        Dim deleteChkBxItem As CheckBox
        Dim sqlconn As New SqlConnection("Initial Catalog=master;Data Source=tcs139054;user id=sa;password=kolkata@1")
        BxsChkd = False
        i = 2
        For Each gv As GridViewRow In DgAddress.Rows
            deleteChkBxItem = gv.FindControl("DeleteThis")
            If deleteChkBxItem.Checked = True Then
                BxsChkd = True
                dgIDs += CType(gv.FindControl("chkid"), HiddenField).Value.ToString + ","
            End If
            i += 1
        If BxsChkd Then
                Dim deleteSQL As String = "delete from employee where Id IN (" & dgIDs.Substring(0, dgIDs.LastIndexOf(",")) & ")"
                Dim cmd As SqlCommand = New SqlCommand(deleteSQL, sqlconn)
            Catch Err As SqlException
            End Try
        End If
    End Sub
 Private Sub FillGrid()
        Dim sqlconn As New SqlConnection("Initial Catalog=master;Data Source=tcs139054;user id=sa;password=kolkata@1")
        Dim sqlcmd As New SqlCommand
        Dim sqldr As SqlDataReader
        sqlcmd.Connection = sqlconn
        sqlcmd.CommandType = Data.CommandType.Text
        sqlcmd.CommandText = "select id,empid,empname from employee"
        sqldr = sqlcmd.ExecuteReader
        DgAddress.DataSource = sqldr
    End Sub

Deepak Kumar Sharma
PGMS Inc(Noida)(India)
Cell No:-9719395072/9313107703
Reply With Quote
  #2 (permalink)  
Old December 7th, 2007, 02:19 PM
Friend of Wrox
Join Date: Aug 2006
Location: Bangalore, Karnataka, India.
Posts: 231
Thanks: 0
Thanked 1 Time in 1 Post

is it is your solution or you have some doubt so that i should read code.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Add Rows to Grid View dpkbahuguna ASP.NET 1.x and 2.0 Application Design 0 March 19th, 2008 04:05 AM
Paging Data grid view Prakash001 Visual Basic 2005 Basics 0 February 6th, 2008 04:07 AM
Deleting rows from a data table in datagrid ann03 ASP.NET 1.x and 2.0 Application Design 1 October 23rd, 2007 06:23 AM
Data Grid View CoolDude C# 2005 3 March 10th, 2007 05:37 AM
Deleting Rows in an Editable Data Grid RichardP ASP.NET 1.0 and 1.1 Professional 2 March 1st, 2006 02:19 PM

All times are GMT -4. The time now is 04:37 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.