Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display two images side by side using item template in repeater.
The images are getting as list collection from solution folder itself. Now i'm getting only one images at a time.

What I have tried:

<asp:Repeater ID="rptSlides" runat="server">
<itemtemplate>

<img src='<%# DataBinder.Eval(Container.DataItem,"Value") %>' class="img-responsive" alt="" style="width: 348px;
height: 188px">







C#:

string[] filePaths = Directory.GetFiles(Server.MapPath("~/MyImages/"));
List<listitem> files = new List<listitem>();
foreach (string filePath in filePaths)
{
string fileName = Path.GetFileName(filePath);
files.Add(new ListItem(fileName, "MyImages/" + fileName));
}
rptSlides.DataSource = files;
rptSlides.DataBind();
Posted
Updated 16-Aug-16 22:29pm
Comments
Karthik_Mahalingam 17-Aug-16 3:13am    
post the complete markup of repeater.
Sathish km 17-Aug-16 4:55am    
<form id="form1" runat="server">
<div>

<div class="thumbnail">

<div id="DemoCarousel" class="carousel slide" data-interval="2000" data-ride="carousel">
<asp:Repeater ID="rptMain" runat="server" OnItemDataBound="OnItemDataBound">
<itemtemplate>
<ol class="carousel-indicators">
<asp:Repeater ID="rptIndicators" runat="server">
<itemtemplate>
<li data-target="#DemoCarousel" data-slide-to='<%# Container.ItemIndex%>' class='<%# Container.ItemIndex == 0 ? "active" : "" %>'>
<%-- <%# Container.ItemIndex%>--%>
</li>


</ol>
<div class="carousel-inner">
<asp:Repeater ID="rptSlides" runat="server">
<itemtemplate>
<div <%# Container.ItemIndex == 0 ? "class=\"item active\"" : "class=\"item\"" %>>
<div class="carousel-caption">
<%-- <img src='<%# DataBinder.Eval(Container.DataItem,"Value") %>' class="img-responsive" alt="" style="width: 300px;
height: 388px">
<img src='<%# DataBinder.Eval(Container.DataItem,"Value") %>' class="img-responsive" alt="" style="width: 300px;
height: 388px">--%>
<%--<img src='http://moss2013-dev/EIP2010/FAS/InternalDocuments/LE_SZ000010_FPI_12_INR_0000122nature-wallpapers-hd-9.jpg' />--%>

<img src='<%# DataBinder.Eval(Container.DataItem,"Value") %>' />

</div>
</div>



</div>



<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span>
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span>
</div>
</div>
</div>
</form>

1 solution

This is more of a css question, but you should add the relevant styles\classes to your image. If you google how to lay things out in a grid you'll find better tutorials, but this is a basic way of doing it

ASP.NET
<asp:Repeater id="rptSlides" runat="server" OnItemDataBound="rptSlides_ItemDataBound">
    <HeaderTemplate>
        <div>
    </HeaderTemplate>
    <ItemTemplate>
        <asp:Image ID="myImage" runat="server" ImageUrl='<%#Eval("ImageUrl") %>' />
    </ItemTemplate>
    <FooterTemplate>
        </div>
    </FooterTemplate>	
</asp:Repeater>


C#
protected void Page_Load(object sender, EventArgs e)
{
    rptSlides.DataSource = new List<MyData> {
        new MyData { ImageUrl = "~/Images/pic1.png" },
        new MyData { ImageUrl = "~/Images/pic2.png" },
        new MyData { ImageUrl = "~/Images/pic3.png" },
        new MyData { ImageUrl = "~/Images/pic4.png" },
        new MyData { ImageUrl = "~/Images/pic5.png" }
    };

    rptSlides.DataBind();
}

protected void rptSlides_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Image myImage = (Image)e.Item.FindControl("myImage");

        // make image float left
        myImage.Style["float"] = "left";

        if (e.Item.ItemIndex % 2 == 0)
        {
            // item index is even so break the floating left
            myImage.Style["clear"] = "both";
        }
    }
}
 
Share this answer
 

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