Problem with a DataList

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
 
S

Senthil Kumar

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top