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

RadRating Not Updating on DataBind()

2 Answers 131 Views
Rating
This is a migrated thread and some comments may be shown as answers.
ViNull
Top achievements
Rank 1
ViNull asked on 23 Jul 2010, 02:54 AM
I have a rating control in a ListView, used for display only.  ViewState is disabled.  When the ListView is databound, the rating control doesn't update to the new values.  This doesn't appear to be a client cache issue as the generated HTML is still at the old values as well.  you can see in the attached tooltip the value is correct, but the display is wrong.

Here is the code in the ListView ItemTemplate:

<telerik:RadRating runat="server" ID="rating" Value='<%# Eval("Score") %>' ReadOnly="true" Skin="Default"  Precision="Exact" EnableToolTips="false"/>
<telerik:RadToolTip runat="server" TargetControlID="rating" Text='<%# Eval("Score","{0:#.##} / 5.0 - ") + Eval("votes","{0:n0} votes") %>' Skin="Sunset" />

You can see this at *removed* (please don't pass around this link as the site is still in development ;) ).  If you change the sort order, the rating controls will not reflect the new values, however clicking a paging link which changes the URL will update the rating control.

2 Answers, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 27 Jul 2010, 03:19 PM
Hi ViNull,
The reason for the problem you describe is that the value of the rating control is persisted in the client state of the control as well. That is why, in this case you have three options:
  • Enable the view state of the ListView control:
    <asp:ListView ID="RadListView1" runat="server" EnableViewState="true">
        <ItemTemplate>
            <%# Eval("Score") %>
            <telerik:RadRating runat="server" ID="rating" DbValue='<%# Eval("Score") %>' ReadOnly="true"
                Skin="Default" Precision="Exact" EnableToolTips="false" />
        </ItemTemplate>
    </asp:ListView>
  • Move the code for data-binding the ListView control to PreRender:
    <asp:ListView ID="RadListView1" runat="server" EnableViewState="false">
            <ItemTemplate>
                <%# Eval("Score") %>
                <telerik:RadRating runat="server" ID="rating" DbValue='<%# Eval("Score") %>' ReadOnly="true"
                    Skin="Default" Precision="Exact" EnableToolTips="false" />
            </ItemTemplate>
        </asp:ListView>
    protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
     
            DataTable dt = new DataTable();
            DataRow dr;
            int rowsNum = 2;
            string[][] colsInfo = {
                new string[] { "Score"},
                new string[] { "votes"}
            };
     
            for (int i = 0; i < colsInfo.Length; i++)
            {
                dt.Columns.Add(colsInfo[i][0]);
            }
     
            var test = 1;
            var test2 = 1;
            if (Page.IsPostBack)
            {
                test = -1;
                test2 = rowsNum;
            }
     
            for (int j = test2; j >= 1 && j <= rowsNum; j = j + (test))
            {
                dr = dt.NewRow();
     
                dr[colsInfo[0][0]] = Convert.ToDecimal(j, NumberFormatInfo.InvariantInfo);
                dr[colsInfo[1][0]] = j + 10;
     
                dt.Rows.Add(dr);
            }
     
            RadListView1.DataSource = dt;
            RadListView1.DataBind();
        }
  • Create a custom control that Inherits from the RadRating control and overrides the LoadPostData method:
    public class RadRatingWithoutState:RadRating
    {
        protected override bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
            //return base.LoadPostData(postDataKey, postCollection);
            return false;
        }
    }

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
ViNull
Top achievements
Rank 1
answered on 27 Jul 2010, 03:31 PM
Thank you for the answer. 
Tags
Rating
Asked by
ViNull
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
ViNull
Top achievements
Rank 1
Share this question
or