Luis Valencia
Luis Valencia

Reputation: 34038

How to add an HyperLink field by code but with an image instead of a text?

I am creating a gridview and one of the columns should be a link, but instead of text I need an icon.

How can I accomplish that?

  HyperLinkField bCSLink = new HyperLinkField();
            bCSLink.NavigateUrl = "CsLink"; ??
            grdiview.Columns.Add(bCSLink);

Upvotes: 0

Views: 352

Answers (2)

Serge
Serge

Reputation: 6712

Use a template field.

            <asp:TemplateField>
            <ItemTemplate>
                <asp:HyperLink ID="myHyperLink" runat="server">
                    <asp:Image ID="imSomething" runat="server" SkinID="Something" />
                    <asp:Image ID="imSomethingElse" runat="server" SkinID="SomethingElse" />
                </asp:HyperLink>
            </ItemTemplate>
            </asp:TemplateField>

Then make the image you want to display Visible and the other ones non Visible.

Upvotes: 0

Amit Singh
Amit Singh

Reputation: 8129

Just Set the Text your HyperLink like this.....

bCSLink .Text = @"<img src='"+ResolveUrl("Path of Image of Delete Icon")+"' /> ";

Upvotes: 1

Related Questions