Click here to Skip to main content
15,903,856 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all
How to delete a row in a gridview with a delete button, with Confirmation. the gridview has no data bound values.
the values are from a text box.
i had set the delete button with button option provided in the gridview itself.

can any help me with the code

thanks in advance
Posted
Comments
Sandeep Mewara 5-Jun-12 5:21am    
And did you try to do it? Where are you stuck?
Ragi Gopi 5-Jun-12 6:02am    
i used the following code
but it is generating error
protected void gv1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
gv1.DeleteRow(e.RowIndex);
}

U can see a post in Code project itself which will let you do that deletion easily, Just refer this-

GridView Delete, with Confirmation[^]
 
Share this answer
 
Comments
Ragi Gopi 5-Jun-12 5:20am    
i have no connection with database
you can add a template field to your grid view and in that add a link button with command argument attribute and set the value to the item ID or KeyName, and then in RowCommand of grid, use this code:
C#
int id = Convert.ToInt32(e.CommandArgument);

its realy base on your data access logic to how to handle the delete event!
for me I use linq to EF and just call the deleteObject method.

for confirmation use onclientclick attribute and use this code:
XML
<asp:LinkButton ID="LinkButton1" OnClientClick="confirm(are you sure to delete this record"
 CommandArgument='<%#Eval("id") %>' runat="server">delete</asp:LinkButton>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900