This is a discussion on How to give confirmation for deleting in datagrid? within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi friends, I need to know how to give confirmation when deleting row in datagrid? Could anybody answer me?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi friends, I need to know how to give confirmation when deleting row in datagrid? Could anybody answer me?
__________________ Krishnakumar.S Beware of Everything -that is un true; stick to the Truth shall succeed slowly but steadily |
| Sponsored Links |
| |||
| we can add the javascript to each and every Delete link button (one per row). We will do that in ItemDataBound event handler. See the following code... Code: Private Sub DataGrid1_ItemDataBound
(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
Handles DataGrid1.ItemDataBound
Dim l As LinkButton
If e.Item.ItemType = ListItemType.Item Or
e.Item.ItemType = ListItemType.AlternatingItem Then
l = CType(e.Item.Cells(0).FindControl("cmdDel"), LinkButton)
l.Attributes.Add("onclick", "return getconfirm();")
End If
End Sub The Confirmation JavaScript function Code: function getconfirm()
{
if (confirm("Do you want to delete record?")==true)
return true;
else
return false;
}
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| You can add confirm message to any html tag like this, Code: <a href="#" onclick="return confirm('Are you sure you want to delete?')">delete</a> ![]()
__________________ S.VinothkumaR Behind me is infinite power, Before me is Endless Possibility, Around me is Boundless Opportunity, Why should I fear! |
| |||
| You notice that I added a TemplateColumn and I wrote myself the ItemTemplate the item template has the following code <a id="lnkDelete" href='<%#DataBinder.Eval(Container,"DataItem.Produ ctID")%>' onclick="return confirm('Are you sure you want to delete')" onserverclick="DeleteProduct" runat="server">delete</a> ------------------------------------------------------------------ the DeleteProduct Method code is here: protected void DeleteProduct(object s, System.EventArgs e) { //Cast the s object to an HtmlAnchor, I'm sure it is an HtmlAnchor HtmlAnchor deleteLnk = (HtmlAnchor)s; //Retrive the ProductID from the HRef attribute int productID = int.Parse(deleteLnk.HRef); //Perform delete procedure. string deleteSql = "DELETE FROM Products WHERE ProductID="+productID; SqlCommand cmdDelete = new SqlCommand(deleteSql,myConn); myConn.Open(); cmdDelete.ExecuteNonQuery(); BindGrid(); myConn.Close(); } ------------------------------------------------------------------------- (or) private void BindGrid() { SqlCommand cmd = new SqlCommand("SELECT * FROM Products",myConn); dgItems.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection) ; dgItems.DataBind(); if(dgItems.Items.Count!=0) { //string that hold the javascript confirm message string confirm = "return confirm('Are you sure you want to delete?')"; foreach( DataGridItem item in dgItems.Items) { LinkButton deleteBtn=(LinkButton)item.Cells[2].Controls[0]; deleteBtn.Attributes.Add("onclick",confirm); } } } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Deleting file contents using php | Archimedees | PHP Programming | 1 | 09-20-2007 02:44 AM |
| deleting specific rows in a table using php | Archimedees | PHP Programming | 6 | 09-14-2007 02:51 AM |
| can i format the hard disk without deleting some files | saravanan | Computer Hardware | 3 | 09-04-2007 06:11 AM |
| Can any one give more info about FTP? | raj | Server Management | 1 | 07-18-2007 01:42 AM |
| Give away ebooks! | drecko | Promotion Techniques | 5 | 02-22-2007 08:43 PM |