Jay1b Posted March 20, 2006 Posted March 20, 2006 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" /> 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. Dim deleteButton As Button = e.Item.Cells(1).FindControl("btnDel") This compiles but doesnt work. Does anyone know how to get this working? Thanks. Quote
shaul_ahuva Posted March 20, 2006 Posted March 20, 2006 Are you looking in the wrong cell or for the wrong id? You could also try e.Item.FindControl (assuming the button's id is unique to the item). I would suggest debugging it, and seeing what the contents of the cells are. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.