views:

13

answers:

1

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?

EDIT:

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" 
    onitemcommand="dtlstScraps_ItemCommand" 
    onitemdatabound="dtlstScraps_ItemDataBound">
    <ItemTemplate>
        <table class="style26">
            <tr>
                <td>
                    <asp:Panel ID="pnlHeader" runat="server" BackImageUrl="~/Images/scraphead.gif" 
                        Height="50px" Width="640px">
                        <table class="style27">
                            <tr>
                                <td class="style28">
                                    &nbsp;</td>
                                <td class="style29">
                                    **<asp:ImageButton ID="ibtnUser" ImageUrl='<%# strPath + DataBinder.Eval(Container.DataItem, "senderPic") %>' CommandName ="ImageClick" runat="server" Height="35px" Width="35px" />**
                                </td>
                                <td class="style34">
                                    <asp:LinkButton ID="lbtnUser" Text='<%#Bind("senderName")%>' CommandName="LinkClick" runat="server">User Page</asp:LinkButton>
                                </td>
                                <td class="style35">
                                    <asp:Label ID="lblTimeStamp" Text='<%#Bind("timestamp")%>' runat="server" ></asp:Label>
                                </td>
                                <td class="style33">
                                    &nbsp;</td>
                            </tr>
                        </table>
                    </asp:Panel>
                    <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>
                    </asp:Panel>
                </td>
            </tr>
        </table>
    </ItemTemplate>

</asp:DataList>
A: 

Try to use

ImageUrl='<%# ThePath + DataBinder.Eval(Container.DataItem, "picName") %>'
andrei m
It doesn't work :(
Robert
could you post the code for asp:DataList and the C# code used for binding? picName must be a property of the DataSource.
andrei m
Code posted in edit.
Robert
Does your code work if you remove strPath from ImageUrl? And what exactly are you meaning by "does not work"? (you receive some kind of error, the output is not what you are expecting, etc)
andrei m
No image is being displayed. (The images do exist at the specified location.)
Robert
try to copy the generated src (from the rendered ImageButton - view source from browser) in a new browser window to see if it opens the file. If not than is not a binding issue.
andrei m
x___x You're right. I think it's not a binding issue. I had a brain fart and was returning a somewhat incorrect string from my strPath property. Sorry to waste time >_>
Robert
it was my pleasure :)
andrei m