Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...