Home > DeveloperSection > Forums > Change AutoGeneratedDelete LinkButton of Gridview to an Image Button
Brad Pitt
Brad Pitt

Total Post:61

Points:429
Posted on    December-11-2014 10:35 PM

 ASP.Net C#  Gridview 
Ratings:


 2 Reply(s)
 3876  View(s)
Rate this:

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.

Thanks! 



Simons Hood
Simons Hood

Total Post:70

Points:494
Posted on    December-12-2014 6:10 AM

Try this

 

<Columns>

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

      ShowDeleteButton="true"/>

</Columns>

And set AutoGenerateDeleteButton="false"


Jayden Bell
Jayden Bell

Total Post:105

Points:739
Posted on    December-12-2014 6:54 AM

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

 

Here's an example of a GridView:

 

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns ="false">

    <Columns>

        <asp:TemplateField>

        <ItemTemplate>

            <asp:LinkButton ID="Link" runat="server" Text="click" OnClick="link_Click"/>

        </ItemTemplate>

        </asp:TemplateField>

        <asp:BoundField DataField="field1" HeaderText="My Column 1" />

        <asp:BoundField DataField="field2" HeaderText="My Column 2" />

     </Columns>

</asp:GridView>

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

}


Don't want to miss updates? Please click the below button!

Follow MindStick