Setting a cssclass on a clicked item

2 posts, 0 answers
  1. Steve
    Steve avatar
    1871 posts
    Member since:
    Dec 2008

    Posted 18 May 2010 Link to this post

    I'm my serverside code I'm setting a css class on a label item in the radrotator

    So then OnClientItemClicked I clear the class from the item, but how the heck do I put that class onto the new item I clicked?

  2. Petio Petkov
    Petio Petkov avatar
    825 posts

    Posted 20 May 2010 Link to this post

    Hi Steve,

    I created for you a simple example which adds a custom css class to the currently clicked element, and removes the css from the previously clicked element. Here it is the code:
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <head runat="server">
        <style type="text/css">
            .CustomStyle span
                color: Red !important;
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <script type="text/javascript">
            var previousElement;
            function RotatorItemClick(rotator, args)
                var item = args.get_item();
                var index = item.get_index();
                var itemElement = item.get_element();
                Sys.UI.DomElement.addCssClass(itemElement, "CustomStyle");
                if (previousElement != null)
                    Sys.UI.DomElement.removeCssClass(previousElement, "CustomStyle");
                previousElement = itemElement;
                    <telerik:RadRotator ID="RadRotator1" runat="server" Width="80px" Height="20px"
                         ScrollDuration="500" FrameDuration="2000" ItemHeight="30" ItemWidth="30"
    protected override void CreateChildControls()
           string[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
           foreach(string month in months)
               RadRotatorItem rotatorItem = new RadRotatorItem();
               Label lbl = new Label();
               lbl.Text = month;

    Let us know if you have any other questions.

    Sincerely yours,
    Petio Petkov
    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