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))))
            
        MyConn.Open()
        Cmd.ExecuteNonQuery()
        MyConn.Close()
        BindData
    End Sub

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

    Sub Page_Load(Source As Object, E As EventArgs)
        If Not Page.IsPostBack Then
            BindData()
        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
        MyDataGrid.DataBind()
    End Sub
    </script>
    </head>
    <body>
    <form id="Form1" runat="server" method="post">
    <asp:Datagrid runat="server"
        Id="MyDataGrid"
        GridLines="Both"
        cellpadding="0"
        cellspacing="0"
        Headerstyle-BackColor="#8080C0"
        Headerstyle-Font-Name="Arial"
        Headerstyle-Font-Bold="True"
        Headerstyle-Font-Size="14"
        BackColor="#8080FF"
        Font-Name="Arial"
        Font-Size="11"
        AlternatingItemStyle-BackColor="#C0C0C0"
        AlternatingItemStyle-Font-Name="Arial"
        AlternatingItemStyle-Font-Size="11"
        BorderColor="Black"
        AllowPaging = "True"
        PageSize = "8"
        PagerStyle-Mode = "NumericPages"
        PagerStyle-HorizontalAlign="Center"
        PagerStyle-PageButtonCount = "10"
        OnPageIndexChanged = "Page_Change"
        AutogenerateColumns="False"
        OnDeleteCommand="MyDataGrid_DeleteCommand"
        DataKeyField="id"
        Width="50%">
        <Columns>
            <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>
        </Columns>
    </asp:DataGrid>
    </form>

  • 12 years ago

    Hi

    I hope this link may solve your problem

    http://www.dotnetjohn.com/articles.aspx?articleid=68

    Hari K......

     

  • 12 years ago

    Hi

    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).

Contribute

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