コンテンツへスキップ

GridViewの削除ボタンに一括で確認ダイアログを入れたい。

  • 対象はGridViewの削除すべて
  • どのGridViewでも対応できるように。
  • 削除コントロールはLink
  • 1つのカラムに複数のControl(削除+編集)がある場合もある。
Dim i As Integer
For i = 0 To tGrid.Columns.Count - 1
    Dim tColumn As DataControlField = tGrid.Columns(i)

    If Not TypeOf (tColumn) Is CommandField Then Continue For

    Dim tCommand As CommandField = DirectCast(tColumn, CommandField)
    If Not tCommand.ShowDeleteButton Then Continue For

    Dim tRow As GridViewRow
    For Each tRow In tGrid.Rows
        Dim tControl As Control
        For Each tControl In tRow.Cells(i).Controls
            If Not TypeOf (tControl) Is IButtonControl Then Continue For
            If DirectCast(tControl, IButtonControl).CommandName <> "Delete" Then Continue For

            ' ここはLinkButton決め打ちだけど、Link以外にも対応したい場合は、追加かな。
            DirectCast(tControl, LinkButton).OnClientClick = "return confirm('削除してもよろしいですか?');"
        Next
    Next
Next

© 2003 Kurusugawa Computer Inc.