DataList Help

T

TCORDON

I have a DataList with a bunch of items (eg. Shoppiong Cart) each Item has a
Remove button, in the code Behind page I have a Sub called Remove Item which
calls a Function like this:

Public Shared Function RemoveItem (t_ItemIndex as Integer) as String

This function removes the item from the DB.

My question is, first how do I tie up the command button for each item so
that when it loads it knows that it represents Item "X" this being the Id of
the item, and second, how do I make him call that function?

TIA!
 
R

Riki

Eliyahu said:
Look in the help for ItemCommand event.

Since it's about deleting, I would rather use the DeleteCommand event.

For the button set CommandName="Delete".

Add the DeleteCommand event handler to the DataList.

For the DataList, also set the DataKeyField property to "ID" (or the name of
the field).

Use code like this:

Sub DataList1_DeleteCommand(Sender As Object, E As DataListCommandEventArgs)
' e.Item is the item that was clicked on
RemoveItem(e.Item.ItemIndex))
BindDataList() ' rebind the datalist
End Sub
 
E

Eliyahu Goldin

Didn't know even about this event. Looks like the only difference between
these 2 events is that in the case of ItemCommand you have to check
CommandName in the event handler.

Eliyahu
 
T

TCORDON

Thanks, I am still getting an error, please let me know if I missed
something.

This is what I have done so far.

1. In the Item Template, I named the Button "cmdDelete" and set its
CommandName Property to: Delete
2. I placed all the code to delete the record inside: Private Sub
lstItems_DeleteCommand(ByVal source.... )

What I am seeing is that that event is not getting fired.

TIA!
 
E

Eliyahu Goldin

You've checked that lstItems_DeleteCommand appears as DeleteCommand event
handler in the datalist property panel, haven't you?

Eliyahu
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top