Setting RadRatingItem values in code behind

6 posts, 0 answers
  1. Kellie
    Kellie avatar
    29 posts
    Member since:
    Feb 2009

    Posted 19 Jul 2010 Link to this post

    I have specified the number of stars in my code behind using:

    numberOfStars = 7;

    ctrlRating.ItemCount = NumberOfStars;

    The values assigned seem to be automatic (e.g. 1, 2, 3, 4, 5, 6, 7) and I would like to override them with my own values (0, 2, 4, 6, 8, 10, 12).

    In this post: http://www.telerik.com/community/forums/aspnet-ajax/rating/tooltips-of-radrating.aspx
    you say "That is why, I would recommend that you wrap the rating control in UpdatePanel and update the items in the Items collection server-side."

    I have tried to update the items and always get an Index out of range error even in the first iteration.

    ctrlRating.Items[numberOfStars - 1].Value = 33

     

     

     

    Can you please provide an example of updating the item values using c sharp?

    Thanks

  2. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 22 Jul 2010 Link to this post

    Hi Kellie,
    Your code for updating the value of a rating item is correct. However, in order to use it, you need to fill the Items collection of the control first. Please refer to the following online demo for information on the Items collection:

    http://demos.telerik.com/aspnet-ajax/rating/examples/itemscollection/defaultcs.aspx

    In case you need to specify a Value, Tooltip, etc for the rating items, you should create those items and add them to the Items collection of the control. In case you simply need a rating control that will render with a certain number of stars, you should use the ItemCount property and leave the Items collection of the control empty.

    Regards,
    Tsvetie
    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. Kellie
    Kellie avatar
    29 posts
    Member since:
    Feb 2009

    Posted 22 Jul 2010 Link to this post

    That's what I thought.
    Since I don't know the amount of stars until runtime, I have to create the items in the code behind.
    When I tried doing that, and then ran my solution, the rating showed up as blank space but I was still able to hover over the blank area and see tooltips.
    I tried assigning an image when adding an item, but this did not help. Still the same behaviour.
    Do I have to assign the image or will it use an image by default?
    If I have to assign an image, do I have to assign to all 3 image url properties?
    Is it behaving like this because it is not in an UpdatePanel?

    Thanks for your help!
  5. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 22 Jul 2010 Link to this post

    Hello Kellie,
    No, you need not set any image for the rating items - in case you have not specified images, the items will use the images from the skin that you have applied to the rating control. The default skin is "Default". I tested the following code and the items appeared as expected:
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
     
        RadRating rating = new RadRating();
        var i=0;
        while (i++ < 7)
        {
            RadRatingItem item = new RadRatingItem();
            item.Value = i;
            item.ToolTip = i.ToString();
            rating.Items.Add(item);
        }
     
        Form.Controls.Add(rating);
    }

    As you mention that you use an update panel, I tested the following scenario:
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Button ID="Button1" runat="server" Text="Get rating control" OnClick="Button1_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>

    protected void Button1_Click(object sender, EventArgs e)
    {
        RadRating rating = new RadRating();
        var i = 0;
        while (i++ < 7)
        {
            RadRatingItem item = new RadRatingItem();
            item.Value = i;
            item.ToolTip = i.ToString();
            rating.Items.Add(item);
        }
     
        UpdatePanel1.ContentTemplateContainer.Controls.Add(rating);
    }

    Again, the rating control showed as expected.

    In case you need additional help with that, it would be best if you open a new support ticket and send me a simple running project that demonstrates the problem you have.

    Best wishes,
    Tsvetie
    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
  6. M
    M avatar
    1 posts
    Member since:
    Mar 2011

    Posted 31 Mar 2011 Link to this post

    Hi,

    I have generated RadRating control with RadRatingitems dynamically. I have provided all images related properties value i.e. imageUrl, HoveredImageUrl, HoveredSelectedImageUrl, SelectedImageUrl.

    But images are not getting displayed. From viewSource it seems that 'a' and 'span' has been created properly.

    Can you help me to find out root cause for that?

    Thanks in advance.
  7. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 05 Apr 2011 Link to this post

    Hi M Shah,

    I tried to reproduce the problem but to no avail. Could you please make sure that the paths to the images are correct?

    For your convenience I have prepared a sample page where the RadRating is dynamically created on page load. Could you please modify the page to a point where the problem occurs and send it back so we can examine it?

    Best wishes,
    Dobromir
    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
UI for ASP.NET Ajax is Ready for VS 2017