0

Little background. I'm taking certain elements from a winforms application and creating a webforms app.

The first element is a Timeline, data for the timeline is stored in a MS SQL database. There are two tables 'timeline' and 'timeLineAttachments'. The timeline table contains the timeline's post text, time posted, post by who etc, if the post has any image attachments then the column 'attachment' will be 'True'. In the timeLineAttachments table there is a refID column which will store the id value from the timeline table.

So if the post has attachments in SQL I would call stored procedure 'getTimeLineAttachments' and pass the ID from the timeline post. Then the stored procedure will return any images where refID = id.

I have added a datalist to my webform and attached it to a stored procedure. Currently I have the following code on my timeline.aspx

<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
        <ItemTemplate>
            <Table Class="table">
                <tr>
                    <td>
            <div class="accountName">
            <asp:Label ID="accountNameLabel" runat="server" Text='<%# Eval("accountName") %>' />
             <br />
            <span class="addedByDetails">
            <asp:Label ID="addedByLabel" runat="server" Text='<%# Eval("addedBy") %>' /> added this Note on  <asp:Label ID="dateTimeLabel" runat="server" Text='<%# Eval("dateTime") %>' />
           <%-- <asp:Label ID="subjectLabel" runat="server" Text='<%# Eval("subject") %>' />--%>
            </span></div>             


            <div id="shell">
            <asp:Label ID="messageLabel" runat="server" Text='<%# Eval("message") %>' />
            </div>    

                <div runat="server" Visible='<%# Eval("attachment")%>'>

                </div>       

                      </td>
                    </tr>
                </table>
        </ItemTemplate>
    </asp:DataList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:smartshadeConnectionString %>" SelectCommand="001Web7DayTimeLine" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

My question is how do I call my stored procedure and then display the returned images. What I want to do is go get the attachments from my timelineAttachments table and display them here:

<div runat="server" Visible='<%# Eval("attachment")%>'>
          *** IF the <%# Eval("attachment")%> is True then I want to get immages from SQL based on the Eval("id") ***  
</div>   

I've look around and I cant find any good tutorials on how to even get close to this. Any help would be appreciated.

  • How are your images stored? Are they byte arrays (or similar) saved in the actual database or are they files saved on the HD and the database holds the path and name of the file? – Steve Dec 08 '15 at 21:22
  • @Steve - The images are stored as byte arrays in the timelineAttachments table. The column name 'smallThumb' – Paul Walker Dec 08 '15 at 21:25
  • So is your question about how to convert the byte array so it can be shown or is it how you could load the image using an EVAL() or is it about how to call a stored procedure using value from your current data context or something else altogether? It wasn't clear. – Steve Dec 08 '15 at 21:35
  • I think I understand. Just noticed that code was in an ItemTemplate. Can I assume your field [SmallThumb] is returned in your [001Web7DayTimeLine] stored procedure? – Steve Dec 08 '15 at 21:39
  • @Steve The question is how do I branch off from the ItemTemplate to get the images from the database using [001Web7DayTimeLine] stored procedure and then display them in ItemTemplate. Yes the Stored Procedure returns the [SmallThumb}. – Paul Walker Dec 08 '15 at 22:47
  • I don't have a computer in front of me to get you the exact code now but you should be able to set the `src` of your `image` to the Eval("SmallThumb") if that field is already in your current data context. Have you tried that? – Steve Dec 08 '15 at 23:27
  • @Steve I do not have SmallThumb in my current data context. I was pulling in the SmallThumb in my original stored procedure with an left join but not all posts have attachments and some posts have multiple attachments. When a post has multiple images then I'm getting the same post three or four times to display all the images (because of they way Left join works). My theory is to only call the [001Web7DayTimeLine] procedure when I know for sure we attachments but I cant figure out how to call the procedure and then display the images. – Paul Walker Dec 08 '15 at 23:49
  • Sound like you need to do this with some pretty advanced JS, which is outside of my expertise. See if this helps you: http://stackoverflow.com/questions/541966/lazy-load-of-images-in-listview?rq=1 – Steve Dec 09 '15 at 15:35

0 Answers0