DataGridCommandEventHandler

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello EveryBody,

How can i assign dynamically the DataGridCommandEventHandler to a
dynamically created link buttons command property.

as i have been trying to do the following
in the ItemDataBound event of the datagrid , I am dynamically creating a
link button and assigning the command property with
DataGridCommandEventHandler ,like below:

LinkButton lButton=new LinkButton();
lButton.Text ="Add Details";
lButton.ID ="flagbutton";
lButton.CommandName="changeFlag";
lButton.Command +=new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.HighRevenuePaxDg_ItemCommand);
//where HighRevenuePaxDg is the datagrid.

I am trying to add the itemcommand event handler of the datagrid, so that
the click of the link button should invoke the event
"HighRevenuePaxDg_ItemCommand".

But i am getting a compile time error at the place where i am assigning the
event to the command property of the link button
lButton.Command +=new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.HighRevenuePaxDg_ItemCommand);

Error:
Cannot implicitly convert type
'System.Web.UI.WebControls.DataGridCommandEventHandler' to
'System.Web.UI.WebControls.CommandEventHandler'

so could anyone of you help me out in solving the problem and also telling
me the cause of the problem.

your expert advice would be highly appreciated.

Rgds
Shiju
 
Shiju:

I believe your issue is a result of the Command event derives from
CommandEventHandler, and the ItemCommand event handler you are specifying
uses a DataGridCommandEventHandler. One way to work around this is to use
the Button_Command event to call the HighRevenuePaxDg_ItemCommand procedure.

For example:

private void Button1_Command(object sender,
System.Web.UI.WebControls.CommandEventArgs e)
{
DataGridCommandEventArgs dgcea = (DataGridCommandEventArgs)e;
DataGrid1_ItemCommand(sender, dgcea);
}

You will not have access to the additional properties of the
DataGridCommandEventArgs in this case, of course. Alternatively, you could
create an overload of the HighRevenuePaxDg_ItemCommand procedure that takes
a CommandEventArgs parameter rather than a DataGridCommandEventArgs
parameter. In either case, you will have to assign the event using the
CommandEventHandler.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


Hello EveryBody,

How can i assign dynamically the DataGridCommandEventHandler to a
dynamically created link buttons command property.

as i have been trying to do the following
in the ItemDataBound event of the datagrid , I am dynamically creating a
link button and assigning the command property with
DataGridCommandEventHandler ,like below:

LinkButton lButton=new LinkButton();
lButton.Text ="Add Details";
lButton.ID ="flagbutton";
lButton.CommandName="changeFlag";
lButton.Command +=new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.HighRevenuePaxDg_
ItemCommand);
//where HighRevenuePaxDg is the datagrid.

I am trying to add the itemcommand event handler of the datagrid, so that
the click of the link button should invoke the event
"HighRevenuePaxDg_ItemCommand".

But i am getting a compile time error at the place where i am assigning the
event to the command property of the link button
lButton.Command +=new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.HighRevenuePaxDg_
ItemCommand);

Error:
Cannot implicitly convert type
'System.Web.UI.WebControls.DataGridCommandEventHandler' to
'System.Web.UI.WebControls.CommandEventHandler'

so could anyone of you help me out in solving the problem and also telling
me the cause of the problem.

your expert advice would be highly appreciated.

Rgds
Shiju
 
Back
Top