Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

How to delete row in a gridview and database both using c# asp.net code?
I am taking place Image Button for delete row in a gridview, So, Please help me.

I do'nt want to Edit and Update.

Thanks in Advance.

Ankit Agarwal
Website Developer
Posted

Googled?
About 650,000 results (0.18 seconds)

Visit Here:
http://www.aspsnippets.com/Articles/ASPNet-GridView---Delete-Row-with-Confirmation.aspx[^]
 
Share this answer
 
Try to do the following

Add ImageButton inside the ItemTemplate of the Gridview
XML
<asp:templatefield headertext="""" itemstyle-width=""2%"><br" mode="hold" xmlns:asp="#unknown" /> <ItemTemplate>
         <asp:ImageButton runat="server"
             CommandName='DeleteItem'
             CommandArgument = '<%# Eval("ID") %>'             
             ImageUrl="";             
 </ItemTemplate>

In GridView OnItemCommand event

C#
{
  if(e.CommandName=="DeleteItem")
  {
       var id = Int32.Parse(e.CommandArgument);
      //Delete Code using the id

       //Rebind GridView
  }
 
Share this answer
 
Comments
[no name] 28-Dec-13 6:36am    
Gridview OnItem command does not exists in .net 2010
Tom Marvolo Riddle 28-Dec-13 6:48am    
Hi ankit,it's a RowCommand Event.Try it in RowCommand
JoCodes 28-Dec-13 7:58am    
Have you mentioned .net2010 in your question?
[no name] 28-Dec-13 6:53am    
Error:- has some invalid arguments
JoCodes 28-Dec-13 8:00am    
Yes, post your code which you tried ...

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