[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

=?Utf-8?B?cm9kY2hhcg==?=

2/23/2004 4:51:00 AM

Guys,

I have a WebForm with a DataGrid on it, that includes the default "Delete" button.

If this button's typer is set to "LinkButton", and is clicked, then it calls ItemClick (as you'd expect.)

If it's set to "PushButton" and is clicked, it posts to the server but otherwise does nothing (including calling ItemClick.) This holds true for all the buttons, and a TemplateColumn with a PushButton and LinkButton in the ItemTemplate. I can't find why, although I do have other webforms that exhibit the correct behaviour.

Any suggestions?

Simon.

3 Answers

=?Utf-8?B?cm9kY2hhcg==?=

2/23/2004 6:01:00 PM

0

If you set the CommandName property of the button to 'Delete' or 'Edit' it will invoke the DataGridCommandEvent. It doesn't matter what ButtonType you are using. You just need to make sure you are using the correct event handler for the command you are trying to perform

You can "hook up" the event handlers to your DataGrid like this

this.dgMyGrid.EditCommand += new DataGridCommandEventHandler(this.CommandEvent)
this.dgMyGrid.DeleteCommand += new DataGridCommandEventHandler(this.CommandEvent)

And your event handler would look something like this

private void CommandEvent(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e

tr

if(e.CommandName == "EDIT"

//do what needs to be done when this button is clicke
}//End i
else if(e.CommandName == "DELETE"

//do what need to be done when this button is clicke
}//End else i
}//End tr
catch(Exception Ex

//handle the exception her
}//End catc
}//End CommandEvent()

=?Utf-8?B?cm9kY2hhcg==?=

2/24/2004 12:31:00 AM

0

Hi Angela

Thanks for your reply. However, that is what I've already done, and what doesn't work. I have two pages with DataGrids containing PushButtons: one works, one doesn't. Working one was done 3 months ago, non-working was done last week

It appears that either a) the function is not called by the event or b) the event does not fire. (or c - something I've missed??

It is baffling, and a big pain for such a simple task: display data, select one

Simon

jared

2/25/2004 6:44:00 PM

0

Simon wrote:
> Hi Angela.
>
> Thanks for your reply. However, that is what I've already done, and what doesn't work. I have two pages with DataGrids containing PushButtons: one works, one doesn't. Working one was done 3 months ago, non-working was done last week.
>
> It appears that either a) the function is not called by the event or b) the event does not fire. (or c - something I've missed??)
>
> It is baffling, and a big pain for such a simple task: display data, select one.
>
> Simon.
>
Hi Simon,

I had a similar problem and searched the web and found that if you
databind the datagrid in the Page_Load method each time, it would work
with a LinkButton but not with a PushButton. The solution that I found
was to put the databinding in the Page_Load event, but only if it was
not a PostBack (c#: !IsPostBack). Then it worked fine.

If you would like the whole explanation, you can find it on the forums
of www.asp.net.

Jared