Hi Jenny,
The DataList control also supports the ItemCommand event
that is raised when a user clicks a button that doesn't
have a predefined command such as edit or delete. You can
use this event for custom functionality by setting a
button's CommandName property to a value you need and then
testing for it in the ItemCommand event handler.
For example:
// C#
private void DataList1_ItemCommand(object source,
System.Web.UI.WebControls.DataListCommandEventArgs e)
{
if (e.CommandName == "AddToCart")
{
// Add code here to add the item to the shopping
cart.
// Use the value of e.Item.ItemIndex to find the
data row
// in the data source.
}
}
Bin Song, MCP
-----Original Message-----
Duh! Yeah sorry that was a No Brainer!
I have this new problem: I'm trying to put some
LinkButton inside a Datalist. But I can't add an event
handlerfor the button. If I double click on the LinkButton, I
get forwarded to the method :
dtlMyDataList_SelectedIndexChanged,but that method is not fired when I click on one of the
buttons at runtime.
How do I go about this? Or is it a bad idea to put a Link
Button in a DataList in the first place?
thanks,
Jenny
.