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

db , mysql Adelaide, Australia
  • 12 years ago
    this is my code i want to put confirm msg box about delete record. if click on YES then record will be delete if No then no action will be performed. Deleting from DataBase using a DataGrid 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

Post a reply

No one has replied yet! Why not be the first?

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.

“Owning a computer without programming is like having a kitchen and using only the microwave oven” - Charles Petzold