473,385 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 1222
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Thanh | last post by:
I created an ASP.NET project and dropped a DataList on the web form. I then wrote a simple class to return data: namespace Playing { public class PositionData { private string name; private...
1
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
0
by: Luis Esteban Valencia | last post by:
Hi, I'm in serious need of help. I have a datalist that will list a number of 'Agents'. When the user selects the edit button of my datalist, I put it into edit mode. When putting the datalist...
6
by: tshad | last post by:
I need to get to a status label I have on my footer section of my datalist. There is no event happening that would go to the footer. I am just doing some processing and want to update the label...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
3
by: Mirek Endys | last post by:
I have DataList as part of DataList item. DataList in DataList. The parent DataList working well including Edit command, that shows Edit template and correctly bind the data into edit template...
2
by: scottls | last post by:
Hi All, Thanks for reading my post. I have been working on getting nested datalists working properly wihtin my framework for many days and I think I'm almost there. See if you could help me...
1
by: David | last post by:
Hi, This one appears a little strange to me. Here is the scenario. I load a datalist the first time a page is run. The page has a !IsPostback and the datalist gets loaded at this point. I...
1
by: AJ | last post by:
Hi all, With the following code in mind : <asp:DataList ID="dlOne" DataKeyField="myField1" DataSource="<%# GetDataSource1()" Runat="server"> <ItemTemplate> Output Value Here! <asp:DataList...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.