I have this code in a tutorial but was coded in c#. What is the equivalent code in VB.NET?
VB Code:
protected void myDataGrid_OnItemDataBound(object sender, DataGridItemEventArgs e) { if(e.Item.FindControl("DeleteLink") != null) { ((LinkButton) e.Item.FindControl("DeleteLink")).Attributes.Add("onClick", "return confirm('Are you sure you wish to delete this item?');"); } }
Basically I have a DataGrid with a DELETE linkbutton on the first column (id=DeleteMe) as a template. When user clicks on the DELETE link, it is suppose to prompt a confirmation.
I tried converting to VB but I am getting an error Specified argument was out of the range of valid values. Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
VB Code:
Sub dgCustomer_OnItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) If Not IsDBNull(e.Item.FindControl("DeleteMe")) Then Dim deleteButton As LinkButton = e.Item.Cells(0).Controls(0) '<-- ERROR HERE deleteButton.Attributes("onclick") = "javascript:return Confirm('Are you sure you want to delete this record?');" End If End Sub




Reply With Quote