locked
using bootstrap carousal with datalist / repeater RRS feed

  • Question

  • User1343581070 posted

    Hi,        I have created a datalist that displays images in VS 2012 . I now want to wrap it in a  bootstrap carousal class so that the images slide automatically . Can I implement this with a datalist or do I have to use a repeater ? Please give me the html markup for binding the datalist / repeater inside the wrapping carousal class

    Thanks & regards

    Sanjish

    Wednesday, June 22, 2016 10:14 AM

Answers

  • User61956409 posted

    Hi Sanjish,

    You could refer to the following sample code to use Bootstrap Carousel plugin with Repeater control.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
        <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
        <style>
            .carousel-inner > .item > img,
            .carousel-inner > .item > a > img {
                width: 70%;
                margin: auto;
            }
        </style>
        <script>
            $(function () {
                $(".item").eq(0).addClass("active");
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="container">
                <br>
                <div id="myCarousel" class="carousel slide" data-ride="carousel">
                    <!-- Indicators -->
                    <ol class="carousel-indicators">
                        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                        <li data-target="#myCarousel" data-slide-to="1"></li>
                        <li data-target="#myCarousel" data-slide-to="2"></li>
                        <li data-target="#myCarousel" data-slide-to="3"></li>
                    </ol>
    
                    <asp:Repeater ID="Repeater1" runat="server">
                        <HeaderTemplate>
                            <div class="carousel-inner" role="listbox">
                        </HeaderTemplate>
                        <ItemTemplate>
                            <div class="item">
                                <img src='<%#Eval("img") %>' width="460" height="345" />
                            </div>
                        </ItemTemplate>
                        <FooterTemplate>
                            </div>
                        </FooterTemplate>
                    </asp:Repeater>
    
    
                    <!-- Left and right controls -->
                    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                        <span class="sr-only">Previous</span>
                    </a>
                    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
                        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                        <span class="sr-only">Next</span>
                    </a>
                </div>
            </div>
    
        </form>
    </body>
    </html>
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("img");
    
            dt.Rows.Add("http://www.w3schools.com/bootstrap/img_chania.jpg");
            dt.Rows.Add("http://www.w3schools.com/bootstrap/img_chania2.jpg");
            dt.Rows.Add("http://www.w3schools.com/bootstrap/img_flower.jpg");
            dt.Rows.Add("http://www.w3schools.com/bootstrap/img_flower2.jpg");
    
            Repeater1.DataSource = dt;
            Repeater1.DataBind();
        }
    }
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 23, 2016 3:28 AM

All replies

  • User61956409 posted

    Hi Sanjish,

    You could refer to the following sample code to use Bootstrap Carousel plugin with Repeater control.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
        <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
        <style>
            .carousel-inner > .item > img,
            .carousel-inner > .item > a > img {
                width: 70%;
                margin: auto;
            }
        </style>
        <script>
            $(function () {
                $(".item").eq(0).addClass("active");
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="container">
                <br>
                <div id="myCarousel" class="carousel slide" data-ride="carousel">
                    <!-- Indicators -->
                    <ol class="carousel-indicators">
                        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                        <li data-target="#myCarousel" data-slide-to="1"></li>
                        <li data-target="#myCarousel" data-slide-to="2"></li>
                        <li data-target="#myCarousel" data-slide-to="3"></li>
                    </ol>
    
                    <asp:Repeater ID="Repeater1" runat="server">
                        <HeaderTemplate>
                            <div class="carousel-inner" role="listbox">
                        </HeaderTemplate>
                        <ItemTemplate>
                            <div class="item">
                                <img src='<%#Eval("img") %>' width="460" height="345" />
                            </div>
                        </ItemTemplate>
                        <FooterTemplate>
                            </div>
                        </FooterTemplate>
                    </asp:Repeater>
    
    
                    <!-- Left and right controls -->
                    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                        <span class="sr-only">Previous</span>
                    </a>
                    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
                        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                        <span class="sr-only">Next</span>
                    </a>
                </div>
            </div>
    
        </form>
    </body>
    </html>
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("img");
    
            dt.Rows.Add("http://www.w3schools.com/bootstrap/img_chania.jpg");
            dt.Rows.Add("http://www.w3schools.com/bootstrap/img_chania2.jpg");
            dt.Rows.Add("http://www.w3schools.com/bootstrap/img_flower.jpg");
            dt.Rows.Add("http://www.w3schools.com/bootstrap/img_flower2.jpg");
    
            Repeater1.DataSource = dt;
            Repeater1.DataBind();
        }
    }
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 23, 2016 3:28 AM
  • User1343581070 posted

    Thank you Fei Han .  It does display the images after every n secs initially. But stops after the first round . Also the images dont slide from left to right and the > and < navigators are missing . Could you please incorporate this functionality .

    Thanks & regards

    Sanjish

    Friday, June 24, 2016 3:55 PM
  • User1343581070 posted

    Hi Fei,

                    Sorry for my last post . I was viewing the web page in visual studios web browser   , so the effects weren't clear. After switching to IE it was perfect.

    Regards

    Sanjish

    Friday, June 24, 2016 4:02 PM