datagrid OnItemCommand handler not executing

R

Rick White

I have an asp.net page on which I have a datagrid. The datagrid works
exactly as I want up to this point: I want to have a pushbutton on the
datagrid that will cause the selected row to a different table. There are
many examples of this, but I can't seem to get the OnItemCommand handler to
fire.

The page is called DraftHitters.aspx and has the C# code in
DraftHitters.aspx.cs. Everything _else_ works great.

Here are some snippets:

In DraftHitters.aspx

<%@ Page language="c#" Codebehind="DraftHitters.aspx.cs"
AutoEventWireup="false" Inherits="Baseball.BatterDraft" %>

<asp:datagrid id=gridResults ... runat="server" ... OnItemCommand="Draft"
.... AutoGenerateColumns="False" ...>
....
<Columns>
<asp:ButtonColumn Text="Draft" ButtonType="PushButton"
CommandName="Draft"></asp:ButtonColumn>
....
</Columns>
....
</asp:datagrid>


In DraftHitters.aspx.cs

public void Draft(object Sender,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
int i;
i=5;
}

I can set a breakpoint on the i=5 line and run with debugging; the
breakpoint is never reached. I can debug the rest of the page, so I know I
have debugging set up properly. The reason that Draft is such a useless
function is that I just want to get the thing to run, then obviously I'll
put real, useful code in it. i=5 is the most trivial line I could think of
that I could set a breakpoing on.

It seems like I am missing something about setting up the handler. Most of
the examples I've seen put the handler in a <script> tag on the aspx page; I
don't want to do that.

Thanks!
 
N

Natty Gur

Hi,

There are two ways to attach event handler to event:

1) Using the onXXX attribute (as you do).
2) Using control event in code behind to add event handler to event
delegate. The easy way to do it is to use properties window of the grid,
select the events tab (the light) and double click on ItemCommand.

I'm using both of them without any problems, try to use the second
option. But I really can’t figure out way the first option doesn’t work
for you (I even try it on simple page).

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top