Raising ItemCommand event from a DataGrid nested in a DataList

M

Matthew

I have a DataGrid nested within a DataList. The DataGrid generates
LinkButtons with specific CommandName values. I cannot figure out how
to trap this event. I need to know which DataGrid LinkButton was
selected.

Thanks in advance.
 
V

Vaibhav

give the link button on the datagrid a command name Like
CommandName="DeleteClick" and then in the itemcommand event for the datagrid
check for the command name like
Private Sub dg_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgWires.ItemCommand

If e.CommandName="DeleteClick" Then

End If

End Sub

HTH
 
M

Matthew Ward

The issue is that DataGrid is nested within a DataList.
Therefore when you try to hook the event up (In InitializeComponent())
using

this.instancesGrid.ItemCommand += new
DataGridCommandEventHandler(InstancesGrid_ItemCommand);

you'll get a "Object reference not set to an instance of an object."
error. That's because the grid doesn't exist yet. Therefore, I've
tried to wait to hook up the event until the parent DataList
ItemDataBound event.

In the ItemDataBound event I had this code:
((DataGrid)e.Item.FindControl("instancesGrid")).ItemCommand += new
DataGridCommandEventHandler(InstancesGrid_ItemCommand);

Although that won't cause an error to be raised, it will not call the
method I'm trying to call (InstancesGrid_ItemCommand). It does call
some event because I can see the page postback, but I'm not sure what
event that is.

Thanks for your help.
 
Joined
May 19, 2010
Messages
1
Reaction score
0
I know this is a 6-year old question, but I wanted to post a link to a blog article I wrote on how to solve this. It's very easy, and just requires the event to be attached at the ASPX level.

Since I can't post the direct link to my blog because of velocity review's stupid 50-post limit, just do a search on Google for "geekteligence datagrid".
 
Joined
May 26, 2010
Messages
1
Reaction score
0
tnx

wow, i really DONT like registering en every forum i visit.
BUT i decided to registar en this just to tell you TNX.

this msg is for AAAAAALL administrators of forosdelweb.com
that dont let you reply on a post of some months old.

when i begin to read this page, i saw 2004 and i say THIS WILL
NOT HELP, but when i saw you post 2010, i feel great.

TNX for your info. this really helped.

and i think 50post limit is stpid too
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top