Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to call a function inside a ItemTemplate at a ListView Control
    text
    copied!<p>I have a ListView Control and need to insert some pictures in the ItemTemplate.</p> <pre><code>&lt;asp:ListView runat="server" ID="VareListView"&gt; &lt;LayoutTemplate&gt; &lt;table cellpadding="2" runat="server" id="tblVarer" style="width:100%;border-collapse:collapse;" &gt; &lt;tr runat="server" id="itemPlaceholder"&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/LayoutTemplate&gt; &lt;ItemTemplate&gt; &lt;tr id="Tr1" style="height:100px" class="tblRow" runat="server" &gt; &lt;td valign="top"&gt; &lt;asp:Image ID="ProduktImage" runat="server" ImageUrl='&lt;%# string.Format("images_produkt/{0}.jpg",Eval("Varenr"))%&gt;' /&gt; &lt;/td&gt; &lt;td valign="top" class=""&gt; &lt;asp:Label ID="LastNameLabel" runat="server" Text='&lt;%# Eval("Varenavn1")%&gt;' /&gt; &lt;br /&gt; &lt;asp:Label ID="FirstNameLabel" runat="server" Text='&lt;%# string.Format("Varenr: {0}",Eval("Varenr")) %&gt;' /&gt; &lt;br /&gt; &lt;asp:Label ID="Varenavn2" runat="server" Text='&lt;%#Eval("Varenavn2") %&gt;' /&gt; &lt;br /&gt; &lt;asp:Label ID="Varenavn3" runat="server" Text='&lt;%#Eval("Varenavn3") %&gt;' /&gt; &lt;br /&gt; </code></pre> <p>at this point I need to insert pictures if a filename contains "Varenr" Something like this</p> <pre><code> DirectoryInfo myDir = new DirectoryInfo(Request.PhysicalPath.Substring(0, Request.PhysicalPath.LastIndexOf("\\")) + "/images_produkt/montering"); FileInfo[] files = myDir.GetFiles(varenr + "*"); if (files.Length != 0) { foreach (FileInfo fil in files) { Image img = new Image(); img.ImageUrl = "/images_produkt/montering/" + fil.Name; img.Height = 20; img.Width = 20; } } </code></pre> <p>But I downt now how to get this to work :) the rest of the ListView code is like this</p> <pre><code> &lt;/td&gt; &lt;td valign="top" align="right" class=""&gt; &lt;asp:Panel ID="Enhet" runat="server" Visible='&lt;%#Eval("Enhet").ToString() != String.Empty %&gt;'&gt; &lt;asp:Label ID="Pris" runat="server" Text='&lt;%# string.Format("{0} kr",Eval("Pris2"))%&gt;' /&gt; &lt;br /&gt; &lt;/asp:Panel&gt; &lt;asp:Label ID="Vekt" runat="server" Text='&lt;%# string.Format("{0} Kg",Eval("Vekt"))%&gt;' /&gt; &lt;br /&gt; &lt;asp:TextBox ID="Antall" runat="server" Text="1" Width="20"&gt;&lt;/asp:TextBox&gt; &lt;asp:Image ID="Image1" runat="server" ImageUrl='style/shoping01.jpg' Width="22" Height="22" /&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre> <p> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload