CSDN博客

img rickjelly2004

在datagrid中删除时确定?(转)

发表于2004/7/1 10:06:00  744人阅读

分类: ASP。NET的经典收藏

在datagrid中删除时确定?(转)

转贴:Andy.m   日期:2003-07-12   人气:37
<%@ Page Language="VB" Debug="true" %>
<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
    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 DataGrid_ItemCreated(Sender As Object, e As DataGridItemEventArgs)

        Select Case e.Item.ItemType
            Case ListItemType.Item
        Dim myDeleteButton As Button
            myDeleteButton = e.Item.FindControl("btnDelete")
         myDeleteButton.Attributes.Add("onclick","return confirm('Are you Sure you want to delete this company?');")

        Case ListItemType.AlternatingItem
                Dim myDeleteButton As Button
            myDeleteButton = e.Item.FindControl("btnDelete")
         myDeleteButton.Attributes.Add("onclick","return confirm('Are you Sure you want to delete this company?');")
           
        End Select

    End Sub

    Sub DataGrid_DeleteRow(sender As Object, e As EventArgs)
        Label1.Text = "HEY, you can't delete that company!"
    End Sub

</script>

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

    <Columns>
    <asp:TemplateColumn HeaderText="Delete?">          
          <ItemTemplate>
               <asp:button id="btnDelete" OnClick="DataGrid_DeleteRow" runat="Server" Text="Delete Row" />
          </ItemTemplate>
    </asp:TemplateColumn>
        </Columns>

       </asp:DataGrid>
       <p>
    </form>
</body>
</html>
0 0

相关博文

我的热门文章

img
取 消
img