Solved

How to delete an item using a checkbox in the datalist using asp.net

Posted on 2004-10-03
3
391 Views
Last Modified: 2008-03-10
Hello........
Can Help Me...

How to delete an item using a checkbox in the datalist using asp.net.................

Also..... there is a button in the datalist....
then... when you have select the check in the checkbox in the datalist.....
you click on the button in the datalist... that will delete... the item... after... you have check the item... that you want... to delete by checking at the checkboxes............


Also,.. can provide me with some of the coding....,,, so that

Maybe...you can also... give me the delete statement for deleting the records in the database.

Thanks aLot......

0
Comment
Question by:fen2009
3 Comments
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 50 total points
ID: 12214610
Why are you using both a checkbox as well as a Delete button.

In case you want to allow the user to select multiple records and then delete all selected records together then use the check box
The code in this case will be
(on the Command button Click)

Private Sub DeleteAll_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles DeleteAll.Click
   Dim isDeleted As Boolean
   Dim anItem As DataListItem

   ' Check each box and see if the item should be deleted.
   For Each anItem In DataList1.Items
      If CType(anItem.FindControl("Delete"), CheckBox).Checked Then
            Dim aTable As DataTable
            aTable = CType(DataList1.DataSource, DataTable)
            aTable.Rows(anItem.ItemIndex).Delete()
      End If
   Next
   DataList1.DataBind()
End Sub


If you want the user to be able to delete individually then use the Delete button for each row.
The code in this case will be

(On the Delete Button Handler)

Private Sub DataList1_DeleteCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) _
Handles DataList1.DeleteCommand
   ' Code to delete the item from the data source.
   Dim aTable As DataTable
   aTable = CType(DataList1.DataSource, DataTable)
   aTable.Rows(e.Item.ItemIndex).Delete()
   ' Bind the data after item is deleted.
   DataList1.DataBind()
End Sub

There's another approach also wherein you would use a Delete SQL Query and then recreate the datalist. I think that you can do based on the above code, in case you want to use that approach.

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

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 79
oracle query help 18 99
how to send memory stream from ics Client To ics server ? 11 82
parse convert xml feed to text (python) 2 70
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
A short article about problems I had with the new location API and permissions in Marshmallow
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

14 Experts available now in Live!

Get 1:1 Help Now