Problem with a DataList

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Guys

I have this problem: I'm trying to put a LinkButton inside a Datalist. But I can't add an event handle
for 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

Jenn
 
The way is to do it through the code.
Add and event ItemCreated event handler to the datalist.
lets say this event handler is DataList1_ItemCreated.
No each time a row for the datalist is created, then this
method is called with the index of the current row. All
you is find the corresponding linkbutton and add an event
to this.

private void DataList1_ItemCreated(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)
{
((LinkButton)e.Item.FindControl
("LinkButton1")).Click = //Your event handler
}

Hope this helps,
Senthil
-----Original Message-----
Hi Guys,

I have this problem: I'm trying to put a LinkButton
inside a Datalist. But I can't add an event handler
for 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?
 
Back
Top