Change AutoGeneratedDelete LinkButton of Gridview to an Image Button

i have a gridview with AutoGenerateDeleteButton Property set true. Of course this property auto generates a linkbutton at the leftmost of the gridview, my question is, how can i change it to an Image Button?? i wanted my gridview to look more presentable by making the control buttons an image.


Last updated:12/12/2014 6:54:36 AM

2 Answers

Anonymous User
Anonymous User

Try this 

   <asp:CommandField ButtonType='Image' DeleteImageUrl='~/Images/DeleteImage.png'

And set AutoGenerateDeleteButton='false'

Jayden Bell
Jayden Bell

You can create a TemplateField and use  autogeneratecolumns='false'. 

Here's an example of a GridView: 

<asp:GridView ID='GridView1' runat='server' AutoGenerateColumns ='false'>
            <asp:LinkButton ID='Link' runat='server' Text='click' OnClick='link_Click'/>
        <asp:BoundField DataField='field1' HeaderText='My Column 1' />
        <asp:BoundField DataField='field2' HeaderText='My Column 2' />

Where field1 and field2 are headers from your DataTable 

And to access the row within the event handler: 

protected void link_Click(object sender, EventArgs e)
    int rowindex = ((GridViewRow)((Control)sender).NamingContainer).RowIndex;
    //do something with rowindex etc