Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Thumbnails are not aligning vertically in listview with bootstrap
here is markup

What I have tried:

ASP.NET
<asp:ListView ID="ListView1" runat="server">
<ItemTemplate>
    <div class="row">    
        <div class="col-sm-6">
            <table style="margin:auto;">
            <tr>
                <td style="margin:auto;width:100px;">
                    <img id="Image2" src='<%# Eval("imagename") %>' alt="hello" style="width:100px;" />
                </td>        
                <td>    
                    <a href="details.aspx?id=<%#Eval("id") %>"><%#Eval("Subject") %></a
                </td>                                                                                        
            </tr>
            </table>
        </div>
</ItemTemplate>
<ItemTemplate>
    <div class="row">    
        <div class="col-sm-6">
            <table style="margin:auto;">
            <tr>
                <td style="margin:auto;width:100px;">
                    <img id="Image2" src='<%# Eval("imagename") %>' alt="hello" style="width:100px;" />
                </td>                                        
                <td>
                    <a href="details.aspx?id=<%#Eval("id") %>"><%#Eval("Subject") %></a
                </td>                                                                                                            
            </tr>
            </table>
        </div>
</ItemTemplate>
</asp:ListView>
Posted
Updated 5-Dec-19 2:57am
v3

1 solution

The key to doing this is to look at the actual HTML that is being rendered, do your style changes within it; and then bringing that back to your NET code.

As a precursor, format what you actually have in your code; using tabs or other fixed spacing. I have noticed a few errors in your template.

The first two appear in your anchor (link) elements; the href does not have a closing quote, and neither the tag opening or closing are terminated properly
HTML
<a href="details.aspx?id=
   <%#Eval("id") %>"><%#Eval("Subject") %>
</a
The second problem I found is that within your template, you do not appear to be closing your row div
HTML
<ItemTemplate>
   <div class="row">
      <div class="col-sm-6">
         <table style="margin:auto;">
            <tr>
               <td style="margin:auto;width:100px;">
                  <img id="Image2" src='<%# Eval("imagename") %>' alt="hello" style="width:100px;" />
               </td>
               <td>
                  <a href="details.aspx?id=
                     <%#Eval("id") %>"><%#Eval("Subject") %>
                  </a
               </td>
            </tr>
         </table>
      </div>
</ItemTemplate>
 
Share this answer
 
Comments
Richard Deeming 5-Dec-19 8:56am    
There's also the two ItemTemplate definitions, which won't work. Perhaps one was meant to be an AlternatingItemTemplate. :)
MadMyche 5-Dec-19 10:40am    
Yea, noticed that, identical code... And all of the images will have an ID of "Image2"
Aftab Iqbal Clips 8-Dec-19 6:17am    
Yes my fault

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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