Click here to Skip to main content
15,559,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I use a delete button in a GridView through Command line using VB Code behind?
Posted
Updated 13-Mar-13 6:57am
v2
Comments
Md Jamaluddin Saiyed 13-Mar-13 11:59am    
I mean to say code behind !!
Richard C Bishop 13-Mar-13 12:01pm    
Well you have one of two options. You can either use the smart tag of the Gridview to enable deleting or you can write a custom event handler that handles the delete button click event, does that make sense?
Md Jamaluddin Saiyed 13-Mar-13 12:05pm    
Thanks ! but I dont want to use smart tag !! How to write a custom event handler ? Can you give me any example Pls ?
Richard C Bishop 13-Mar-13 12:11pm    
Ok, have a look at my solution below. It is a rough draft of something you will want.

1 solution

This is just an example of what the event handler would look like:

protected void gvEntries_RowDeleting(object sender, GridViewDeleteEventArgs e)
       {
           //This will depend on how you are obtaining your data. If the data is from a database, you will have to delete the record in the database before databinding in order for the gridview to reflect it.
           gvEntries.DeleteRow(e.RowIndex);
           gvEntries.DataBind();
       }


Also, you will want to add "gvEntries_RowDeleting"(or whatever you name your gridview and its deleting event) to the onrowdeleting event attribute of your gridview markup.
 
Share this answer
 
v4

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