PushButton v. LinkButton in a DataGrid

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

I have two buttons in a DataGrid. If I leave the ButtonType = "LinkButton",
the EditCommand and DeleteCommand events fire fine. If I change th
ButtonType = "PushButton", the events do not fire. Does this buttonType
property change how the events fire? Suggestions? I have the ItemCommand
event wired up to, but that only fires for the LinkButton as well.

A few code samples below ...

Thanks!

Mark

*** Code - I left out the brackets intentionally as I wasn't sure if they'd
get mangled when sent via email. ***

** The following will fire the EditCommand event.
asp:ButtonColumn Text="Edit" CommandName="Edit" ButtonType="LinkButton"

** The following will NOT fire the EditCommand event.
asp:ButtonColumn Text="Edit" CommandName="Edit" ButtonType="PushButton"

this.DataGrid1.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCom
mand);
this.DataGrid1.EditCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCom
mand);
this.DataGrid1.DeleteCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteC
ommand);
 
Got it to work. I don't understand it, but it works. Below is all I
changed:

Old code in Page_Load:

dgSir.DataBind();

New Code in Page_Load:

if (!IsPostBack)
{
dgSir.DataBind();
}

So, why would the PushButton be affected by a re-binding of the data, but
the LinkButton wouldn't?

Thanks.

Mark
 
Back
Top