Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add image to a link button in asp.net

Tags:

c#

asp.net

<asp:GridView ID="Grid_Organisationtable" runat="server"  CssClass="string"
             SelectedIndex="0" DataKeyNames="OrganisationID"
            ShowHeaderWhenEmpty="True" OnRowDeleting="Grid_Organisationtable_RowDeleting" OnRowEditing="Grid_Organisationtable_RowEditing"
            AutoGenerateColumns="false" Height="95px" Width="492px">     
<Columns>
                   <asp:TemplateField HeaderText="Edit Controls" ItemStyle-Width="15%">
                        <ItemTemplate>
                            <asp:ImageButton ImageUrl="~/Styles/Images/Edit.jpg" CommandName="Edit" runat="server"
                                ID="btn_Edit" ToolTip="Edit Organisation" />
     <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("OrganisationID") %>' CommandName="Delete" runat="server">delete</asp:LinkButton>
     </ItemTemplate>
                        <ItemStyle Width="15%" />
                    </asp:TemplateField>

I am having a link button in the grid view to delete a row from the grid, I want to add a image to the link button instead of the text delete. how can I add image to the link button. I dont want to use image button. Thanks.

like image 856
Mark Avatar asked Sep 16 '11 13:09

Mark


3 Answers

Place an tag in between the

<asp:LinkButton>

and

</asp:LinkButton>

tags, just like you would a normal hyperlink.

 <asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("OrganisationID") %>' CommandName="Delete" runat="server"><img src="pathtoimage.jpg" alt="delete group" />delete</asp:LinkButton> 
like image 74
David Avatar answered Oct 05 '22 05:10

David


Will this not work?:

<asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("OrganisationID") %>' CommandName="Delete" runat="server">
    <asp:Image ID="Image1" runat="server" ImageUrl="/images/someimage.jpg" style="border-width: 0px;" />
</asp:LinkButton> 
like image 21
James Johnson Avatar answered Oct 05 '22 05:10

James Johnson


I didn't use text property of link button and did this:

<asp:LinkButton ID="lbtag" runat="server" CausesValidation="false">
  <asp:Image ID="imgdelete" runat="server" ImageUrl="images/delete.jpg" />
  <%# Container.DataItem %>
</asp:LinkButton>
like image 31
SumairIrshad Avatar answered Oct 05 '22 05:10

SumairIrshad