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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Editable Datagrid

Status
Not open for further replies.

MaddogC

Programmer
Dec 4, 2003
134
GB
I have an editable datagrid, to which I have added an "Add" button into the footer.

To do this I have changed the column containing the delete button from a buttonColumn to a template column

Previously a confirm delete attribute was added to the delete button in the OnItemDataBound code as follow:-

Dim deleteButton as linkButton = e.Item.Cells(4).Controls(0)
deleteButton.Attributes("onclick") = "javascript:return confirm('Are you sure you want to delete" & DataBinder.Eval(e.Item.DataItem, "Surname") & "?')"

I need to provide the same functionalty but referencing my delete button within my template column. How do I do this?

 
In your ItemDatabound sub, check if your e.item.itemtype is a footer. If it isn't, add your confirm function to your button.

Let me know if you're getting an error. Maybe your button is not at the position .Item.Cells(4).Controls(0) anymore...
 
I'm using the 4guys datagrid examples as a guide. In article he gives an example of deleting a row. This uses the boundcolumn. in the adding a new row article the buttoncolumn containing the delete button is changed to a templatecolumn to accommodate the add button in the footer.

This is where I then have the problem referencing the original delete button as it is no longer a linkbutton therefore

Dim deleteButton as linkButton = e.Item.Cells(4).Controls(0)

no longer works.
 
Managed to sort this now. I thought i'd tried this, but the following works.

Dim myDeleteButton As Button
myDeleteButton = e.Item.FindControl("btnDelete")
myDeleteButton.Attributes.Add("onclick","return confirm('Are you sure you want to delete?');")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top