Gridview Delete Query

J

JN

I am using the sqldatasource to populate a gridview and I have a pop up that
fires when the item_deleting event is triggered.

Now in the popup, if the user clicks cancel, i dont want the delete query to
continue.

How do I accomplish this?
Thanks.
JN
 
A

Andrew Robinson

JN,

Not sure how you are able to force a popup within the event handler but you
can set the SqlDataSourceCommandEventArgs Cancel property to true:

protected void SqlDataSource1_Deleting(object sender,
SqlDataSourceCommandEventArgs e)
{
e.Cancel = true;
}

A better way to handle this whole thing is to add a popup directly to your
delete button. (You will need to use a templated field for your button.) If
the user clicks on the Cancel button, the event is cancelled at the browser.
Much cleaner. Works with any of the asp.net button controls. Take a look at
the OnClientClick property:

<asp:LinkButton ID="LinkButtonDelete" runat="server"
CausesValidation="False" CommandName="Delete"
OnClientClick="return confirm('Delete Record?');" Text="Delete" />

Hope this helps.
 
J

JN

Thanks Andrew, I will try your suggestions.

Andrew Robinson said:
JN,

Not sure how you are able to force a popup within the event handler but
you can set the SqlDataSourceCommandEventArgs Cancel property to true:

protected void SqlDataSource1_Deleting(object sender,
SqlDataSourceCommandEventArgs e)
{
e.Cancel = true;
}

A better way to handle this whole thing is to add a popup directly to your
delete button. (You will need to use a templated field for your button.)
If the user clicks on the Cancel button, the event is cancelled at the
browser. Much cleaner. Works with any of the asp.net button controls. Take
a look at the OnClientClick property:

<asp:LinkButton ID="LinkButtonDelete" runat="server"
CausesValidation="False" CommandName="Delete"
OnClientClick="return confirm('Delete Record?');" Text="Delete" />

Hope this helps.
 
J

JN

Onclientclick worked like a champ...thanks!

Andrew Robinson said:
JN,

Not sure how you are able to force a popup within the event handler but
you can set the SqlDataSourceCommandEventArgs Cancel property to true:

protected void SqlDataSource1_Deleting(object sender,
SqlDataSourceCommandEventArgs e)
{
e.Cancel = true;
}

A better way to handle this whole thing is to add a popup directly to your
delete button. (You will need to use a templated field for your button.)
If the user clicks on the Cancel button, the event is cancelled at the
browser. Much cleaner. Works with any of the asp.net button controls. Take
a look at the OnClientClick property:

<asp:LinkButton ID="LinkButtonDelete" runat="server"
CausesValidation="False" CommandName="Delete"
OnClientClick="return confirm('Delete Record?');" Text="Delete" />

Hope this helps.
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top