Share via

Image link in datagrid

Andrew Deegan 1 Reputation point
2021-11-20T03:03:27.627+00:00

Hi, I have the following datagrid. Is there a way to add an additional field that has an image (spotify) and a link from my database. Lets call the image location "spotify.jpeg" and the datafield "Link" (I've reduced the settings for convenience):

    <asp:DataGrid id="dgAlbum" runat="server" 
                <Columns>
                    <asp:boundcolumn DataField="Title"></asp:boundcolumn>
                </Columns>
    </asp:DataGrid>

Any help appreciated

Andy

Developer technologies | ASP.NET Core | Other
0 comments No comments

1 answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,106 Reputation points
    2021-11-20T06:46:41.307+00:00

    Hi @Andrew Deegan ,
    As far as I think, you could use NavigateUrl in the HyperLink Field to direct to the path you need. And you could use image src to show the image.Just like this:

    <asp:DataGrid runat="server" ID="dgAlbum">  
                    <Columns>  
                         <asp:boundcolumn DataField="Title"></asp:boundcolumn>  
                        <asp:TemplateColumn>  
                            <ItemTemplate>  
                                <asp:HyperLink runat="server" ID="ht" NavigateUrl='<%#Eval("filepath") %>'>  
                                   <image src='<%#Eval("imagepath") %>'></image>  
                                </asp:HyperLink>  
                            </ItemTemplate>  
                        </asp:TemplateColumn>  
                    </Columns>  
                </asp:DataGrid>  
    

    Best regards,
    Yijing Sun


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.