471,089 Members | 1,273 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

DataList and delete

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

Nov 28 '05 #1
2 1422
Harold try posting what you are trying to do
Patrick

<ha*********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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

Nov 29 '05 #2
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.

Nov 29 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Chris Fink | last post: by
3 posts views Thread by Hardy Wang | last post: by
4 posts views Thread by jenn | last post: by
5 posts views Thread by TCORDON | last post: by
3 posts views Thread by Verde | last post: by
4 posts views Thread by Nathan Sokalski | last post: by
7 posts views Thread by =?Utf-8?B?cGF0cmlja2RyZA==?= | last post: by
3 posts views Thread by Crazy Cat | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.