RadRating Not Updating on DataBind()

3 posts, 0 answers
  1. ViNull
    ViNull avatar
    2 posts
    Member since:
    Feb 2009

    Posted 22 Jul 2010 Link to this post

    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. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 27 Jul 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. ViNull
    ViNull avatar
    2 posts
    Member since:
    Feb 2009

    Posted 27 Jul 2010 Link to this post

    Thank you for the answer. 
Back to Top