
Here's my code:
var oRotator = $find('<%=radRotateNews.ClientID %>');
var index = oRotator.get_currentItem().get_index();
Thanks,
Kirk
3 Answers, 1 is accepted
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.
Svetlina
the Telerik team

<%@ 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;
}
}
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">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
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.
Svetlina
the Telerik team