DataGrid/ButtonColumn

S

Simon

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.
 
A

Angela

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()
 
S

Simon

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
 
J

jared

Simon said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,102
Messages
2,570,641
Members
47,244
Latest member
Robertfem

Latest Threads

Top