0

我需要向网格添加确认删除操作。问题是“删除”链接的呈现方式。我的网格是在 vb.net 后面的代码中构建的。我有这个

colDelete.AllowDelete = True
colDelete.Width = "100"
AddHandler CType(gridSavedForLater, Grid).DeleteCommand, AddressOf dgDeleteSelectedIncident

子如下

Sub dgDeleteSelectedIncident(ByVal sender As Object, ByVal e As GridRecordEventArgs)

    Dim message As String = "Are you sure you want to delete this incident?"
    Dim caption As String = "Confirm Delete"
    Dim result = System.Windows.Forms.MessageBox.Show(message, caption, Windows.Forms.MessageBoxButtons.OKCancel, Windows.Forms.MessageBoxIcon.Warning)

    'If (result = Windows.Forms.DialogResult.Cancel) Then
    'Else
    ' MessageBox("Are you sure you want to delete this incident?")
    'Get the VehicleId of the row whose Delete button was clicked
    'Dim SelectedIncidentId As String = e.Record("IncidentId")

    ''Delete the record from the database
    'objIncident = New Incidents(SelectedIncidentId, Session("userFullName"))

    'objIncident.DeleteIncident()
    ''Rebind the DataGrid
    LoadSavedForLater()
    ''        End If

End Sub

调用此子时,我需要添加一个 javascript 确认对话框。我可以使用 Windows 窗体消息框来做到这一点,但这在服务器上不起作用。

请帮助乔

4

2 回答 2

5

您不能在 ASP.NET 中显示 MessageBox,因为它将显示在服务器上。所以你需要一个confirm删除按钮的javascript onclick。因此,您不需要先回发到服务器。您可以将脚本附加到GridView.

一个好地方RowDataBoundGridView

Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
    Select Case e.Row.RowType
        Case DataControlRowType.DataRow
            ' if it's a custom button in a TemplateField '
            Dim BtnDelete = DirectCast(e.Row.FindControl("BtnDelete"), Button)
            BtnDelete.OnClientClick = "return confirm('Are you certain you want to delete?');"
            ' if it's an autogenerated delete-LinkButton: '
            Dim LnkBtnDelete As LinkButton = DirectCast(e.Row.Cells(0).Controls(0), LinkButton)
            LnkBtnDelete.OnClientClick = "return confirm('Are you certain you want to delete?');"            
    End Select
End Sub
于 2012-05-16T14:46:47.153 回答
0

作为替代方案,在网页中通知用户状态更改(保存、删除、更新等)的常用方法是在 HTML 中添加更新元素。基本上,您将为用户设置一个标签(或其他标签)。

“您的更改已成功保存。” “尝试保存更新时遇到错误。” , 例如。您可以将红色设置为错误或任何您的编程心脏想要的样式。

我有点喜欢这种方法,因为弹出窗口对我来说总是更像 WinForm 的东西。要么工作,所以我只是想我会建议另一种方法。

于 2012-05-16T15:12:57.630 回答