Problem Initializing edit command in a datagrid

Posted on 2006-05-09
Last Modified: 2008-02-01
this is my datagrid edit command function

private void dgProjects_EditCommand(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
                              Label mylabel;
                              mylabel = ((Label)e.Item.FindControl("ProjectID"));
                              Response.Redirect("projects.aspx?Page=1&ProjectID=" + mylabel);

when I add this link to the InitializeComponent function

      private void InitializeComponent()
                  this.dgProjects.EditCommand += new System.EventHandler(this.dgProjects_EditCommand); this line has the error
                  this.dgProjects.SelectedIndexChanged += new System.EventHandler(this.dgProjects_SelectedIndexChanged);


I get
does not match delegate void(system.eventhandler)

any ideas


Question by:jcook32
    LVL 25

    Expert Comment

    EditCommand is a DataGridItemEvent delegate, not a plain Event delegate.


                  this.dgProjects.EditCommand += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgProjects_EditCommand);


    Author Comment

    did not work
    get an error on this part of the line
    this.dgProjects.EditCommand += new

    error is:
    Cannot implicitly convert type 'System.Web.UI.WebControl.datagriditemeventhandler to
    LVL 25

    Accepted Solution

    Sorry, I didn't read which event you were hooking up to.  You're using the wrong type of event handler.  The DataGridItemEventHandler is used for ItemCreated and ItemDataBound (I assume you copied the method from somewhere else).

    You need to change the signiature of your event handler to:

    private void dgProjects_EditCommand(object sender, System.Web.UI.WebControls.DataGridCommandEventArgs e)
                             Label mylabel;
                             mylabel = ((Label)e.Item.FindControl("ProjectID"));
                             Response.Redirect("projects.aspx?Page=1&ProjectID=" + mylabel);

    and use

    this.dgProjects.EditCommand  += new DataGridCommandEventHandler(this.dgProjects_EditCommand);


    Author Comment

    That worked thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    737 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

    20 Experts available now in Live!

    Get 1:1 Help Now