Basically the same thing is happening as we saw before, except this is happening out of the UI.
Handling Events
The last thing to discuss is how to handle events raised by controls inside your repeater/datalist/datagrid. Events raised from controls inside your repeater bubble up to the repeater and are exposed via the OnItemCommand event. LinkButtons and Buttons have a CommandArgument and CommandName property which lets the OnItemCommand handler figure out which button was clicked, for example:
In the above code, two linkbuttons can raise events, either deleting the customer [4-9] or adding an order [11-16]. Also note that the ItemCommand is hooked up [1]:
1: protected void eventRepeater_ItemCommand(object s, RepeaterCommandEventArgs e) {
2: int customerId = Convert.ToInt32(e.CommandArgument);
3: switch (e.CommandName.ToUpper()){
4: case "DELETE":
5: CustomerUtility.DeleteCustomer(customerId);
6: BindEventRepeater(false);
7: break;
8: case "Add":
9: //doesn''''t actually do antyhing right now.
10: break;
11: }
12: }
Depending on what the commandName is [3] we know different actions were requested. Its important to note that if you change the underlaying datasource (like deleting a row) and want that to be visible to the user, you need to rebind your repeater/datalist/datagrid. Also note that if you are caching your data, like I am here, you''''ll need to invalidate the cache so that the new data source (with the delete/added/updated rows) is used.
Download
This sample web application simply contains a number of pages which do various things with repeaters. It should provide a playground for trying different things and simply messing around with databinding: