get_index() not working

4 posts, 0 answers
  1. Kirk Thomas
    Kirk Thomas avatar
    23 posts
    Member since:
    Aug 2009

    Posted 30 Sep 2010 Link to this post

    I'm trying to get the index of the current item in a rotator but when I use the get_index() function the value is undefined.  When I debug and look at the available methods in the get_currentItem() function I don't see get_index() listed.  What am I doing wrong? 

    Here's my code:

    var oRotator = $find('<%=radRotateNews.ClientID %>');
    var index = oRotator.get_currentItem().get_index();

    Thanks,

    Kirk
  2. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 30 Sep 2010 Link to this post

    Hello Kirk Thomas,

     I am not sure why this does not work on your side because it works on ours. You can examine the following online demo:

    http://demos.telerik.com/aspnet-ajax/rotator/examples/clientapi/defaultcs.aspx

    As you see, when the current item is clicked, get_index() method is used to retrieve the index and it is shown as value and not as undefined.

    This being said, what I can assume is that for some reason you have an invalid setup. Would you please prepare a very simple reproduction page which is fully runnable and share its code here along with detailed explanations, controls and browser version information? Once we are able to observe and debug the setup on our side, we will do our best to help.

    Greetings,
    Svetlina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kirk Thomas
    Kirk Thomas avatar
    23 posts
    Member since:
    Aug 2009

    Posted 30 Sep 2010 Link to this post

    The getIndex() function does not work with this code.  Is this what you needed?

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        
    </head>
    <body>
    <script type="text/javascript">
        function GetIndex() {

            var oRadRotator = $find('<%=RadRotator1.ClientID %>');
            var index = oRadRotator.get_currentItem();
            var o = index.get_index();
        }
        </script>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <telerik:RadRotator ID="RadRotator1" runat="server" AppendDataBoundItems="true" RotatorType="Buttons">
                
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Container.DataItem %>'></asp:Label>
                </ItemTemplate>
            </telerik:RadRotator>
        </div>
        <a href="#" onclick="GetIndex()">◄</a>
        </form>
    </body>
    </html>

    c# code:

    public partial class Default4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            RadRotator1.DataSource = RotatorData();
            RadRotator1.DataBind();
                
        }

        private string[] RotatorData()
        {
            string[] test = { "test", "test2", "test3" };

            
            return test;
        }
    }
  5. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 01 Oct 2010 Link to this post

    Hi Kirk Thomas,

     I examined the provided code and the current index is not undefined but always 0. This is so because of the incorrect settings of the rotator - all the items are actually visible and you should use the Width and ItemWidth properties to adjust correct configuration:

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <head id="Head1" runat="server">
        <title></title>
    </head>
    <body>
      
        <script type="text/javascript">
            function GetIndex()
            {
      
                var oRadRotator = $find('<%=RadRotator1.ClientID %>');
                var index = oRadRotator.get_currentItem();
                var o = index.get_index();
                alert(o);
            }
        </script>
      
        <script type="text/C#" runat="server">
          
          
            protected void Page_Load(object sender, EventArgs e)
            {
                RadRotator1.DataSource = RotatorData();
                RadRotator1.DataBind();
      
            }
      
            private string[] RotatorData()
            {
                string[] test = { "test", "test2", "test3" };
      
      
                return test;
            }
      
          
              
        </script>
      
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <telerik:RadRotator ID="RadRotator1" runat="server" AppendDataBoundItems="true" Width="140"
                ItemWidth="100" RotatorType="Buttons">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Container.DataItem %>'></asp:Label>
                </ItemTemplate>
            </telerik:RadRotator>
        </div>
        <a href="#" onclick="GetIndex()">◄</a>
        </form>
    </body>
    </html>

    Width this code the indices returned are different and correct.

    The only other thing I can assume that might be causing the problem on your side is that you are using a very old version of the rotator when this method has not been defined and thus you get undefined. If so, please upgrade and test again.

    All the best,
    Svetlina
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top