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>
Enter your message below
Sign in or Join us (it's free).