Solved

Being stupid - ItemCommand trigger not firing

Posted on 2004-04-21
2
567 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
Comment Utility
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
Comment Utility
Thanks Zulu, that was it - it's always something simple isn't!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

763 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

13 Experts available now in Live!

Get 1:1 Help Now