Solved

Being stupid - ItemCommand trigger not firing

Posted on 2004-04-21
2
568 Views
Last Modified: 2012-08-14
When clicking on my commands in my datagrid, the ItemCommand is not getting fired

Item command in c#:
private void dgDocList_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
      //Get the document id of the selected document and store in viewstate.
      _docId = int.Parse(e.Item.Cells[0].Text);
      ViewState["docId"] = _docId;

      switch(e.CommandName)
      {                        
      case "Copy":
      break;
      case "Delete":
      DeleteDocument();
      break;
      case "Edit":
      EditDocument();
      break;      
      case "More":
      break;      
      default:
      // Do nothing.
      break;
      }      
}

First part of ASP code:
<asp:DataGrid id="dgDocList" runat="server" Width="747px" AutoGenerateColumns="False">
<AlternatingItemStyle CssClass="altItemStyle"></AlternatingItemStyle>
<ItemStyle CssClass="itemStyle"></ItemStyle>
<HeaderStyle CssClass="headerStyle"></HeaderStyle>
<Columns>
<asp:BoundColumn Visible="False" DataField="Document_ID">
<ItemStyle Width="1px"></ItemStyle>
</asp:BoundColumn>
<asp:ButtonColumn Text="Edit" CommandName="Edit" ItemStyle-Width="30px"></asp:ButtonColumn>
                        
Any ideas?  I've set a break point on the ItemCommand function and it's never reached.

This has to be something obvious that I'm missing, I'm sure, as I have this functionality working in other projects, and to my eye they don't look any different.

TIA
Ben
0
Comment
Question by:bjohns33
2 Comments
 
LVL 6

Accepted Solution

by:
zulu_11 earned 500 total points
ID: 10877327
Most probably your ItemCommand Signature from the  IntializeComponent() is missing..this has happended to me a number of time using the VS.IDE...

just add the signature back in the IntializeComponent() as

this.dgDocList.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgDocList_ItemCommand);

I'm assuming that dgDocList is the id of the Datagrid that you are using...

Regards

Zulu
0
 
LVL 1

Author Comment

by:bjohns33
ID: 10878806
Thanks Zulu, that was it - it's always something simple isn't!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get String split 5 47
WKHTMLTOPDF - --disable-smart-shrinking not working 10 36
Class object 2 26
Error in JQuery 5 38
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now