DataList and delete

H

haroldsphsu

Hi all,

I created a DataList on a WebForm, and I want to have a separate delete
button at the bottom of the page. I can create a event handler for the
delete button and delete the selected item and re-bind the DataList.
That's working fine. But just curious, how can I tie the delete button
to the DeleteCommand of the DataList? I tried setting the delete
button CommandName property to "Delete", but it won't go to the
DataList DeleteCommand event handler. Does that mean to use the
DeleteCommand, it has to be defined within an ItemTemplate?

Thanks,
Harold
 
H

haroldsphsu

Here's some relevant code:

Public Class TestDataList
Inherits System.Web.UI.Page

Protected WithEvents DataList1 As DataList
Protected WithEvents Button1 As Button

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Me.Page.IsPostBack Then
Dim arr As ArrayList
arr = New ArrayList
arr.Add("foo")
arr.Add("bar")
arr.Add("baz")
DataList1.DataSource = arr
DataList1.DataBind()
End If

Button1.CommandName = DataList1.DeleteCommandName
AddHandler DataList1.DeleteCommand, AddressOf
Me.DataList1_DeleteCommand
End Sub

Private Sub DataList1_DeleteCommand(ByVal sender As Object, ByVal e
As DataListCommandEventArgs)

End Sub

End Class


The button is defined outside the DataList (i.e., not in ItemTemplate
or EditItemTemplate). I want to be able to click the button and
trigger the DataList.DeleteCommand. The code above doesn't do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top