how to put confirm message box when delete records from datagrid.

  • 12 years ago

     this is my code i want add confirm msg box when click on the link of delete text. if click on YES button then record will be delete if no then no action will be performed.

     <script language="VB" runat="server">
    Sub MyDataGrid_DeleteCommand(s As Object, e As DataGridCommandEventArgs )
        Dim strConn as String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
                & "DATA SOURCE=" _
                & Server.MapPath("nwind.mdb;")
            Dim DeleteCmd As String = "DELETE from login Where ID= @ID"
            Dim MyConn As New OleDbConnection(strConn)
            Dim Cmd As New OleDbCommand(DeleteCmd, MyConn)
            Cmd.Parameters.Add(New OleDbParameter("@ID", MyDataGrid.DataKeys(CInt(e.Item.ItemIndex))))
    End Sub

    Sub Page_Change(sender As Object, e As DataGridPageChangedEventArgs)
        MyDataGrid.CurrentPageIndex = e.NewPageIndex
    End Sub

    Sub Page_Load(Source As Object, E As EventArgs)
        If Not Page.IsPostBack Then
        End If
    End Sub

    Sub BindData()
            Dim strConn As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
                       & "DATA SOURCE=" _
                       & Server.MapPath("nwind.mdb;")
            Dim MySQL As String = "Select * from login"
            Dim MyConn As New OleDbConnection(strConn)
        Dim ds as DataSet=New DataSet()
            Dim Cmd As New OleDbDataAdapter(MySQL, MyConn)
            Cmd.Fill(ds, "login")
            MyDataGrid.DataSource = ds.Tables("login").DefaultView
    End Sub
    <form id="Form1" runat="server" method="post">
    <asp:Datagrid runat="server"
        AllowPaging = "True"
        PageSize = "8"
        PagerStyle-Mode = "NumericPages"
        PagerStyle-PageButtonCount = "10"
        OnPageIndexChanged = "Page_Change"
            <asp:ButtonColumn Text="Delete"  HeaderText="Delete" CommandName="Delete"></asp:ButtonColumn>
            <asp:BoundColumn DataField="firstname" HeaderText="fname"></asp:BoundColumn>
            <asp:BoundColumn DataField="lastname" HeaderText="lname"></asp:BoundColumn>
            <asp:BoundColumn DataField="username" HeaderText="uname"></asp:BoundColumn>
            <asp:BoundColumn DataField="pw" HeaderText="pw"></asp:BoundColumn>

  • 12 years ago


    I hope this link may solve your problem

    Hari K......


  • 12 years ago


    i have not found anything related to my question please send me other site if u know

    thanks for sending me the site

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson