This is a migrated thread and some comments may be shown as answers.

Setting RadRatingItem values in code behind

5 Answers 206 Views
Rating
This is a migrated thread and some comments may be shown as answers.
Kellie
Top achievements
Rank 1
Kellie asked on 19 Jul 2010, 06:23 PM
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

5 Answers, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 22 Jul 2010, 03:53 PM
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
0
Kellie
Top achievements
Rank 1
answered on 22 Jul 2010, 04:10 PM
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!
0
Tsvetie
Telerik team
answered on 22 Jul 2010, 08:44 PM
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
0
M
Top achievements
Rank 1
answered on 31 Mar 2011, 03:51 PM
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.
0
Dobromir
Telerik team
answered on 05 Apr 2011, 01:57 PM
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
Tags
Rating
Asked by
Kellie
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Kellie
Top achievements
Rank 1
M
Top achievements
Rank 1
Dobromir
Telerik team
Share this question
or