PC Review


Reply
Thread Tools Rate Thread

DataGrid OnDeleteCommand

 
 
RN1
Guest
Posts: n/a
 
      7th Mar 2008
A DataGrid, populated with records from a database, has a LinkButton
in the ItemTemplate of a TemplateColumn. I want that when this
LinkButton is clicked, users should first be displayed a JavaScript
confirm dialog. If the user clicks OK in the confirm dialog, then the
record should be deleted but if the user clicks the Cancel button in
the confirm dialog, then that record shouldn't be deleted (i.e.
nothing should happen). This is how I tried it in the OnItemDataBound
event handler of the DataGrid:

--------------------------------------------------------------------------------
Sub Item_DataBound(ByVal obj As Object, ByVal ea As
DataGridItemEventArgs)
If (ea.Item.ItemType = ListItemType.Item Or ea.Item.ItemType =
ListItemType.AlternatingItem) Then
Dim lkb As LinkButton

lkb = CType(ea.Item.FindControl("lkbDelete"), LinkButton)
lkb.Attributes.Add("OnClick", "javascript:return
confirm('Delete Record?')")
End If
End Sub
--------------------------------------------------------------------------------

The above code works fine but if I put the above code in the
OnDeleteCommand event handler of the DataGrid (instead of in the
OnItemDataBound event handler), then the JavaScript confirm dialog
doesn't pop-up. Why?

Moreover, if I comment the "If" condition in the above code (in the
Item_DataBound event handler), then the following error gets
generated:

Object reference not set to an instance of the object.

pointing to the lkb.Attributes.Add line in the above code. What causes
this error?

Thanks,

Ron
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MVVM: Single datagrid row selection when a datagrid contains anotherdatagrid in side RowDetailsTemplate Sunita@.NET Microsoft C# .NET 0 12th Nov 2010 09:03 AM
OndeleteCommand does not fire Iain Microsoft ASP .NET 1 27th Feb 2007 03:26 PM
DataGrid OnDeleteCommand Problem Defty Microsoft ASP .NET 2 28th May 2004 10:43 AM
Added CheckBox to a DataGrid Doesn't work with DataGrid.Enabled=False Amar Microsoft ASP .NET 0 6th Apr 2004 11:14 AM
OnDeleteCommand Not Refreshing Page Terry Cox, MCSD Microsoft ASP .NET 0 24th Oct 2003 09:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:05 AM.