Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I confirm delete using datagrid control?

Status
Not open for further replies.

Ken011

MIS
Oct 13, 2006
66
0
0
US
Greetings,

I am using datagrid control to insert, update, display and delete records.

I am have a lot of success implementing all of the above.

What I can't seem to get to work so far is confirming a delete before you actually delete.

For instance,

When I click the delete image, I would like to get an alert box that says, "are you sure you want to delete?"

Does anyone have any ideas what I am doing wrong?

From what I have read so far, you can accomplish this with an onItemDatabound event but I am using that for record viewing.

So, I tried using client side (javascript) validation which I think is actually better because it is faster but again, the record just gets deleted with no alert popping up.

Here are some code snips.

Code:
					<script language="javascript">
<!--

   function ondeleteclick()
   {
        return confirm("Are you sure you want to delete this?")
   }
 
   for(i=0;i<document.all.length;i++)
   {
       var x = document.all.item(i)
       if(x!=null && x.name !=null &&  x.name.indexOf("MyDataGrid")==0)
       {
           if(x.value=="Delete")
                x.onclick = ondeleteclick
           continue;
      }
 }
//-->
</script>

then the datagrid id:

Code:
<asp:DataGrid id="MyDataGrid" runat="server"

then the delete button:

Code:
<asp:ButtonColumn Text="<img border=0 src=images/icon_delete.gif>" CommandName="Delete"></asp:ButtonColumn>

so, why is it not firing?

Thanks in advance
 
It will make it easier for you if you use a TemplateColumn with a Button inside it as you will be able to add the javascript function directly to the button. There's an example of this here that you should follow.


------------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
 
Nowhere in your button code are you calling the js delete function. Mark's suggestion will help you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top