Datagrid wire SelectedIndexChanged event from linkbutton

A

Alex

I have a datagrid with some dynamically generated columns containing
linkButtons. How can I wire these events to fire the
datagrid_SelectedIndexChanged?

When clicking a template column defined in the IDE it works fine, the
event fires. However, anything that I add in code does not fire this
event?

Any idea?

Thanks

Alex
 
G

Guest

I should note that generally speaking, adding controls to a datagrid like you
are doing is not a good idea. Your code is generally much cleaner if you use
template columns. I have not checked this code, but this should work:
lkButton.Click += new EventHandler(DataGrid1_SelectedIndexChanged);

where lkButton is your Button and DataGrid1_SelectedIndexChanged is your
datagrid selected index changed method. It is important to note that the
sender object will be a LinkButton and not a DataGrid row or anything like
that.

Hope that helps!

Jason Lind
 
A

Alex

Jason,

Thanks for the reply. I am using a Template column in code to add the
columns. How can I have the button inside my template column fire the
datagrid SelectedIndexChanged?

Thanks

Alex
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top