I've been looking at a 4GuysfromRolla article on datagrids which has been very useful. However they give an example of tieing a delete button column to the itemdatabound command which allows a custom Javascript message to be shown to the user.
<asp:ButtonColumn Text="Delete" CommandName="Delete" ButtonType="PushButton" />
In a later example they show you how to add new rows, which displays an add button to the bottom of the list where the delete buttons are. However the way the delete buttons are created are different, namely using a template instead of a boundcolumn. This example doesnt have the javascript check in it. I can do something similar using the onClientClick command, but not a custom message.
This didnt compile so i change a line to this.
This compiles but doesnt work.
Does anyone know how to get this working?
Thanks.
<asp:ButtonColumn Text="Delete" CommandName="Delete" ButtonType="PushButton" />
Visual Basic:
Sub dgDepartmentHead_ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
' First, make sure we're NOT dealing with a Header or Footer row
If e.Item.ItemType <> ListItemType.Header And _
e.Item.ItemType <> ListItemType.Footer Then
'Now, reference the PushButton control that the Delete ButtonColumn
'has been rendered to
Dim deleteButton As Button = e.Item.Cells(1).Controls(0)
'We can now add the onclick event handler
deleteButton.Attributes("onclick") = "javascript:return " & _
"confirm('Are you sure you want to delete the " & _
DataBinder.Eval(e.Item.DataItem, "Department") & " department?')"
End If
End Sub
In a later example they show you how to add new rows, which displays an add button to the bottom of the list where the delete buttons are. However the way the delete buttons are created are different, namely using a template instead of a boundcolumn. This example doesnt have the javascript check in it. I can do something similar using the onClientClick command, but not a custom message.
This didnt compile so i change a line to this.
Visual Basic:
Dim deleteButton As Button = e.Item.Cells(1).FindControl("btnDel")
This compiles but doesnt work.
Does anyone know how to get this working?
Thanks.