– How do I combine a string with a variable in Bind() in an .aspx file for a DataList? – Education Career Blog

I’ve searched for this, but maybe I’m using the wrong keywords.

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.

I have a protected property in my codebehind called strPath.

I want to combine it with a database value in my aspx file. Like so:

... ImgUrl = '<%#strPath+ Bind("senderPic")%>' ...

But this doesn’t work. How can I do this?


HEre’s the entire code for the DataList as asked. (The problem is in the ibtnUser element.

<asp:DataList ID="dtlstScraps" runat="server" CellSpacing="4" 
        <table class="style26">
                    <asp:Panel ID="pnlHeader" runat="server" BackImageUrl="~/Images/scraphead.gif" 
                        Height="50px" Width="640px">
                        <table class="style27">
                                <td class="style28">
                                <td class="style29">
                                    **<asp:ImageButton ID="ibtnUser" ImageUrl='<%# strPath + DataBinder.Eval(Container.DataItem, "senderPic") %>' CommandName ="ImageClick" runat="server" Height="35px" Width="35px" />**
                                <td class="style34">
                                    <asp:LinkButton ID="lbtnUser" Text='<%#Bind("senderName")%>' CommandName="LinkClick" runat="server">User Page</asp:LinkButton>
                                <td class="style35">
                                    <asp:Label ID="lblTimeStamp" Text='<%#Bind("timestamp")%>' runat="server" ></asp:Label>
                                <td class="style33">
                    <asp:Panel ID="Panel2" runat="server" Height="60px">
                        <asp:Label ID="lblMsg" runat="server" BackColor="#C9C9C9" BorderColor="#020246" 
                            BorderStyle="Solid" Height="50px" Text='<%# Bind("message") %>' Width="631px"></asp:Label>



Try to use

ImageUrl='<%# ThePath + DataBinder.Eval(Container.DataItem, "picName") %>'

Leave a Comment