Click here to Skip to main content
15,889,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using a grid view which has a delete image button for every row , i want to delete the row on clicking the image button the row should get deleted..
please help me out
Posted
Comments
Thanks7872 3-Feb-15 6:13am    
Have you tried something? Google?
manishmns12 3-Feb-15 6:18am    
yes i had i had


protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{


if (e.CommandName == "Delete")
{
SqlDataSource3.Delete();
GridView1.DataBind();
}

} and the Image button has commandname = delete
manishmns12 3-Feb-15 6:19am    
how can i do this by using command name,...please help me out
Tushar sangani 3-Feb-15 6:23am    
Get the row index of that row and this row index throwe delete this image

you need to do like this


XML
<asp:TemplateField ShowHeader="False">
             <ItemTemplate>
                  <asp:ImageButton ID="Button1" runat="server" CausesValidation="False" ImageUrl="~/script/delete.gif" CommandArgument='<%# eval("MyRowId") %>' CommandName="Select"
                       AlternateText="Delete"></asp:ImageButton>
             </ItemTemplate>
        </asp:TemplateField>





C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string name = e.CommandName;
        if(name=="delete")
           {
               //delete code 
           }
         GridView1.DataBind();
    }
 
Share this answer
 
v4
Comments
manishmns12 3-Feb-15 6:43am    
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.


how to get rid of this?
manishmns12 3-Feb-15 6:52am    
CommandArgument="id of the row by using eval function"

how to get this...please help me
Pranay Rana 3-Feb-15 7:00am    
CommandArgument='<%# eval("MyRowId") %>' here myrowid is you database primary key column name

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