关于如何 确认删除的另外一个办法。

80酷酷网    80kuku.com

  <pre>
<% Page Language="VB" %>
<html>
<head>
    <script language="VB" runat="server">

    Sub Page_Load(Sender As Object, e As EventArgs)
        If Not IsPostBack Then
            Dim values As New ArrayList()

            values.Add(New PositionData("Microsoft", "Msft"))
            values.Add(New PositionData("Intel", "Intc"))
            values.Add(New PositionData("Dell", "Dell"))

            myDataGrid.DataSource = values
            myDataGrid.DataBind()
        End If

    ' add a client click event to the button
        Page.RegisterOnSubmitStatement("OnSubmit", "if(button == 'Delete Company')return confirm('Are you Sure you want to delete this company?');")

    End Sub

    Public Class PositionData

        Private myName As String
        Private myTicker As String

        Public Sub New(newName As String, newTicker As String)
            Me.myName = newName
            Me.myTicker = newTicker
        End Sub

        Public ReadOnly Property Name() As String
            Get
                Return myName
            End Get
        End Property

        Public ReadOnly Property Ticker() As String
            Get
                Return myTicker
            End Get
        End Property
    End Class

    Sub MyDataGrid_Delete(Sender As Object, E As DataGridCommandEventArgs)
    Label1.Text = "HEY, you can't delete " & MyDataGrid.DataKeys(CInt(E.Item.ItemIndex)) & "!"
    End Sub

    Sub MyDataGrid_ItemCreated(Sender As Object, e As DataGridItemEventArgs)

        Select Case e.Item.ItemType
            Case ListItemType.Item, ListItemType.AlternatingItem
        Dim myTableCell As TableCell
        myTableCell = e.Item.Cells(0)
            Dim myDeleteButton As Button
            myDeleteButton = myTableCell.Controls(0)
             myDeleteButton.Attributes.Add("OnClick","button=this.value")
        
        'Notice that it is cell 1 instead of 0
        myTableCell = e.Item.Cells(1)
            myDeleteButton = myTableCell.Controls(0)
             myDeleteButton.Attributes.Add("OnClick","button=this.value")

        End Select

    End Sub

</script>

</head>
<body>
    
    <asp:Label id="Label1" runat="Server" />
    
    <form runat=server>
       <asp:DataGrid id="myDataGrid"
           DataKeyField="Name"
           AutoGenerateColumns="True"
       OnDeleteCommand="MyDatagrid_Delete"
       OnItemCreated="MyDataGrid_ItemCreated"
           runat="server">

    <Columns>
        <asp:ButtonColumn Text="No OnSubmit" CommandName="NoSubmit" ButtonType="PushButton"/>
        <asp:ButtonColumn Text="Delete Company" CommandName="Delete" ButtonType="PushButton"/>
        </Columns>

       </asp:DataGrid>
       <p>

       <asp:TextBox id="TokenTextBox" runat="Server" Columns="40" Text="The required field validator will not fire" />
       <asp:RequiredFieldValidator id="TokentValidator" runat="Server" ControlToValidate="TokenTextBox" />
    </form>
</body>
</html>
</pre>

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: