locked
Binding Concatnation RRS feed

  • Question

  • User-1974089095 posted

     

        <div class="br-bm-gd-lt" runat="server" style='background:url('+"<%#"~/Images/Projects/"+ Eval("PostImage") %>"+")"'   >
                                     



                                    this is a div inside listveiw itemtemplate   what i need is retrive image path inside bacground-image :url()  for every item

    so

    i need the right  server format to do it with concatination

    thanks in advance

    Thursday, September 7, 2017 12:32 AM

Answers

  • User-707554951 posted

    Hi mohamedramzy780,

    From your description, you would bind data to image from url and show the path of image.

    You could refer to the following code:

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function () {
                $("#test").click(function () {     
                    var bg = $(this).css('background-image');
                    bg = bg.replace('url(', '').replace(')', '').replace(/\"/gi, "");
                    alert(bg);
                });
            });
        </script>
    <asp:ListView ID="ListView1" DataSourceID="SqlDataSource1" runat="server">
                    <LayoutTemplate>
                        <table cellpadding="2" width="640px" border="1" runat="server" id="tblProducts">
                            <tr runat="server">
                                <th runat="server">Image</th>
                                <th runat="server">name</th>
                                <th runat="server">age</th>
                            </tr>
                            <tr runat="server" id="itemPlaceholder" />
                        </table>
                    </LayoutTemplate>
                    <ItemTemplate>
                        <tr runat="server">
                            <td>
                                <div id="test" style="width: 50px; height: 50px; background-image: url('<%#"../image/"+ Eval("Image") %>')">aaa</div>
                            </td>
                            <td>
                                <asp:Label ID="FirstNameLabel" runat="Server" Text='<%#Eval("name") %>' />
                            </td>
                            <td valign="top">
                                <asp:Label ID="LastNameLabel" runat="Server" Text='<%#Eval("age") %>' />
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:ListView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [User]"></asp:SqlDataSource>

    Output:

    Best regards

    Cathy

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 7, 2017 9:16 AM