Link to home
Start Free TrialLog in
Avatar of rp
rpFlag for Portugal

asked on

asp.net vb.net gridview image column with link

In a gridview how can create a link in an image field
Avatar of mohan_sekar
mohan_sekar
Flag of United States of America image

use <asp:ImageButton>
Hi,

Please review the attached code as an example on how to format a link from a thumbnail image in a gridview.

/Carl.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" BackColor="#DFDFDF" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" DataKeyNames="PhotoID" DataSourceID="SqlDataSource1" EmptyDataText="There are no images to display." Font-Names="Arial" Font-Size="8pt" ForeColor="#3366CC" Width="800px">
    <Columns>
        <asp:HyperLinkField DataNavigateUrlFields="PhotoID" DataNavigateUrlFormatString="DisplayImage.aspx?PhotoID={0}&amp;fullSize=True"
                        DataTextField="PhotoID" DataTextFormatString="&lt;img src=&quot;DisplayImage.aspx?PhotoID={0}&amp;fullSize=False&quot; style=&quot;border:solid 1px #000000;&quot; alt=&quot;Picture hosted at norrbom.nu&quot;&gt;" Text="Thumbnail:">
                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                    </asp:HyperLinkField>
                    <asp:BoundField DataField="Submitted" HeaderText="Submitted:" SortExpression="Submitted" />
    </Columns>
    <PagerSettings Position="TopAndBottom" />
    <AlternatingRowStyle BackColor="White" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" />
</asp:GridView>

Open in new window

Avatar of rp

ASKER

I put DataTextFormatString = <img src=imagens/{0}/>, and apparently works for my purpose, but the html rendered in browser is :
<img src="imagens/img1.jpg/"/>  
Below img1.jpg appears a "/"       and should not appear. What is wrong in my DataTextFormatString
ASKER CERTIFIED SOLUTION
Avatar of carlnorrbom
carlnorrbom
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial