Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want images to align horizontally so that one image fits to width of div and other images overflow-x and can be seen by sliding.

What I have tried:

I have tried a single row listview setting the column width=100% image width=100% table and div width = 100% with overfflow-x to auto but it has not worked. my code is as follows:
<asp:ListView ID="ListView1" runat="server" DataKeyNames="PhotoGalleryID"  DataSourceID="SqlDataSource1">
                <ItemTemplate>
                    <td runat="server" style="width:100%;">P
                       
                       <img src='<%# "/PhotoGallery/"+Eval("PhotoName") %>' style="width:100%" />
                        <br />
                       
                    </td>
                </ItemTemplate>
                <LayoutTemplate>
                    <table runat="server" border="0" style="width:100%; overflow-x:auto;">
                        <tr id="itemPlaceholderContainer" runat="server">
                            <td id="itemPlaceholder" runat="server"></td>
                        </tr>
                    </table>
                    <div style="width:100%; overflow-x:auto">
                    </div>
                </LayoutTemplate>
                
            </asp:ListView>
Posted
Updated 26-Feb-21 3:26am

1 solution

You haven't told us what "not working" means. But you shouldn't need the table at all:
ASPX
<asp:ListView ID="ListView1" runat="server" DataKeyNames="PhotoGalleryID" DataSourceID="SqlDataSource1">
<LayoutTemplate>
    <div style="width:100%;overflow-x:auto;">
        <div id="itemPlaceholder" runat="server"></div>
    </div>
</LayoutTemplate>
<ItemTemplate>
    <div style="width:100%;">
        <img src='<%# Eval("PhotoName", "~/PhotoGallery/{0}") %>' alt="" style="display:block;margin:0 auto;max-width:100%;" />
    </div>
</ItemTemplate>
</ListView>
 
Share this answer
 
Comments
Member 10235977 26-Feb-21 12:14pm    
I tried it but it displays images vertically, not horizontally. only difference is that earlier i was getting first image almost 100% width and other images very small almost 0% all together in 100% width whereas now i am getting all images 100% width each but aligned vertically. I even tried display inline. it does not help.
Richard Deeming 2-Mar-21 8:22am    
Try changing the container to:
<div style="min-width:100%;overflow-x:auto;">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900