Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I combine a string with a variable in Bind() in an .aspx file for a DataList?
    text
    copied!<p>I've searched for this, but maybe I'm using the wrong keywords.</p> <p>I have a DataList containing an ImageButton whose ImageUrl property I want to set by combining it with a string returned from a codebehind file property and a database value.</p> <p>I have a protected property in my codebehind called <code>strPath</code>.</p> <p>I want to combine it with a database value in my aspx file. Like so:</p> <pre><code>... ImgUrl = '&lt;%#strPath+ Bind("senderPic")%&gt;' ... </code></pre> <p>But this doesn't work. How can I do this?</p> <p>EDIT:</p> <p>HEre's the entire code for the DataList as asked. (The problem is in the <code>ibtnUser</code> element.</p> <pre><code>&lt;asp:DataList ID="dtlstScraps" runat="server" CellSpacing="4" onitemcommand="dtlstScraps_ItemCommand" onitemdatabound="dtlstScraps_ItemDataBound"&gt; &lt;ItemTemplate&gt; &lt;table class="style26"&gt; &lt;tr&gt; &lt;td&gt; &lt;asp:Panel ID="pnlHeader" runat="server" BackImageUrl="~/Images/scraphead.gif" Height="50px" Width="640px"&gt; &lt;table class="style27"&gt; &lt;tr&gt; &lt;td class="style28"&gt; &amp;nbsp;&lt;/td&gt; &lt;td class="style29"&gt; **&lt;asp:ImageButton ID="ibtnUser" ImageUrl='&lt;%# strPath + DataBinder.Eval(Container.DataItem, "senderPic") %&gt;' CommandName ="ImageClick" runat="server" Height="35px" Width="35px" /&gt;** &lt;/td&gt; &lt;td class="style34"&gt; &lt;asp:LinkButton ID="lbtnUser" Text='&lt;%#Bind("senderName")%&gt;' CommandName="LinkClick" runat="server"&gt;User Page&lt;/asp:LinkButton&gt; &lt;/td&gt; &lt;td class="style35"&gt; &lt;asp:Label ID="lblTimeStamp" Text='&lt;%#Bind("timestamp")%&gt;' runat="server" &gt;&lt;/asp:Label&gt; &lt;/td&gt; &lt;td class="style33"&gt; &amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/asp:Panel&gt; &lt;asp:Panel ID="Panel2" runat="server" Height="60px"&gt; &lt;asp:Label ID="lblMsg" runat="server" BackColor="#C9C9C9" BorderColor="#020246" BorderStyle="Solid" Height="50px" Text='&lt;%# Bind("message") %&gt;' Width="631px"&gt;&lt;/asp:Label&gt; &lt;/asp:Panel&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/ItemTemplate&gt; &lt;/asp:DataList&gt; </code></pre>
 

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