locked
Displayed linked picture in Gridview RRS feed

  • Question

  • User876561910 posted

    Hi

    Let’s say I have a database with:
    Place_ID
    Place_Name
    Place_picture

     

    For example
    Place_ID = 123
    Place_Name = Everest
    Place_picture = https://commons.wikimedia.org/wiki/File:Everest_kalapatthar.jpg#/media/File:Everest_kalapatthar.jpg

     

    Place_ID = 465
    Place_Name = Grand Canyon
    Place_picture = https://commons.wikimedia.org/wiki/File:Nankoweap.JPG#/media/File:Nankoweap.JPG

    How do I get this linked to picture to show in the grid view Or I could save the picture to a folder in the website, how would I show this (but I would rather just link to wikipeadia)

    I show this on a Gridview like this (the picture is not showing obviously)

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <%@ Page Language="C#" %>
    <html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
    
    <head runat="server">
    <meta content="en-gb" http-equiv="Content-Language" />
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>Untitled 1</title>
    </head>
    
    <body>
    
    <form id="form1" runat="server">
    		<asp:GridView id="gridview1" runat="server" allowpaging="True" AllowSorting="True" 
    		AutoGenerateColumns="True" 
    		DataSourceID="my_data_source" 
    		ShowHeader="True">
    		<Columns>
    			<asp:boundfield DataField="Place_Name">
    			</asp:boundfield>
    			<asp:boundfield DataField="Place_picture">
    			</asp:boundfield>
    		</Columns>
    		</asp:GridView>
    		<asp:AccessDataSource ID="some_name" runat="server" DataFile="myDatabase.mdb" SelectCommand="SELECT [Place_Name], [Place_picture] FROM [my_table]">
    		</asp:AccessDataSource>
    
    </form>
    
    </body>
    
    </html>
    



    Friday, March 29, 2019 2:12 PM

Answers

  • User-1038772411 posted

    You can try below code to display image in GridView which stored as a link in database. I have used simple HTML img tag to display image.

    <asp:GridView ID="gvImages" CssClass="Gridview" runat="server" AutoGenerateColumns="False"
    HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="white">
    <Columns>
    <asp:BoundField HeaderText = "Image Name" DataField="ImageURL" />
    <asp:TemplateField HeaderText="Image">
    <ItemTemplate>
    <img src='<%# Eval("ImageURL") %>' Height="150" Width="150" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 29, 2019 2:20 PM