471,078 Members | 856 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

DataList Help

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!
Nov 19 '05 #1
5 1159
Look in the help for ItemCommand event.

Eliyahu

"TCORDON" <tc******@hotmail.com> wrote in message
news:uX**************@TK2MSFTNGP15.phx.gbl...
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!

Nov 19 '05 #2
Eliyahu Goldin wrote:
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

--

Riki
Nov 19 '05 #3
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

"Riki" <ri**@nospam.com> wrote in message
news:e$**************@TK2MSFTNGP15.phx.gbl...
Eliyahu Goldin wrote:
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

--

Riki

Nov 19 '05 #4
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!
"Riki" <ri**@nospam.com> wrote in message
news:e$**************@TK2MSFTNGP15.phx.gbl...
Eliyahu Goldin wrote:
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

--

Riki

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

Eliyahu

"TCORDON" <tc******@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
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!
"Riki" <ri**@nospam.com> wrote in message
news:e$**************@TK2MSFTNGP15.phx.gbl...
Eliyahu Goldin wrote:
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

--

Riki


Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Thanh | last post: by
1 post views Thread by bill yeager | last post: by
10 posts views Thread by Bharat | last post: by
reply views Thread by Luis Esteban Valencia | last post: by
6 posts views Thread by tshad | last post: by
3 posts views Thread by Mirek Endys | last post: by
2 posts views Thread by scottls | last post: by
1 post views Thread by David | last post: by
1 post views Thread by AJ | last post: by
reply views Thread by leo001 | 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.