Hello. I have broken down my problem into a very simple page and I'm sure the solution is simple as well. I do need to rebind the grid (not in this example but in my real scenario I do) and my question is why the Rate event is triggered a second time when rebinding the grid? I have already handled the Rate event, saved my rating to the database, and as a final step I want to rebind the grid so that some other data is updated, for example some average rating or something like that. (My grid template column is much more advanced in the real scenario with lots of controls that needs to be updated when a new rating has been saved).
I've played around alot with simple binding, advanced binding and all sorts of things but right now my example looks like below. Please tell me how to solve this.
Here is the Code Behind
and the aspx
Thanks!
I've played around alot with simple binding, advanced binding and all sorts of things but right now my example looks like below. Please tell me how to solve this.
Here is the Code Behind
public void Page_Load(object sender, System.EventArgs e){ if (!IsPostBack) { FillGrid(); }}public void FillGrid(){ RadGridItemRateSimple.DataSource = new ItemRateDTOService().GetItemsBySearchCriterion(new ItemSearchCriterion());}protected void RadGridItemRate_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e){ FillGrid();}protected void RadGridItemRate_ItemDataBound(object sender, GridItemEventArgs e){ if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem) { ItemRateDTO itemRateDTO = (ItemRateDTO)e.Item.DataItem; RadRating radRating = (RadRating)e.Item.FindControl("RadRatingItem"); if (radRating != null) { radRating.DbValue = CommonFunctions.SetDecimal(itemRateDTO.GetAvgRating()); } }}protected void RadRatingItem_Rate(object sender, EventArgs e){ RadRating radRating = (RadRating)sender; GridDataItem dataItem = (GridDataItem)radRating.Parent.Parent; long itemID = CommonFunctions.SetLong(RadGridItemRateSimple.MasterTableView.DataKeyValues[dataItem.ItemIndex]["Item.ID"]); Rating rating = new RatingService().GetSpecificRatingForUser(itemID, ActiveUserID); if (rating == null) rating = new Rating(); rating.ItemID = itemID; rating.Rate = Convert.ToInt32(radRating.Value * 10); rating.CreatedBy = ActiveUserID; new RatingService().Save(rating); RadGridItemRateSimple.Rebind();}and the aspx
<telerik:RadGrid ID="RadGridItemRateSimple" OnItemDataBound="RadGridItemRate_ItemDataBound" OnNeedDataSource="RadGridItemRate_NeedDataSource" runat="server" Width="850px" AllowSorting="True" AllowPaging="true" PagerStyle-Position="TopAndBottom" PageSize="30" AutoGenerateColumns="False" BorderWidth="0"> <MasterTableView DataKeyNames="Item.ID"> <Columns> <telerik:GridTemplateColumn ItemStyle-VerticalAlign="Top" HeaderText="" SortExpression="ItemName"> <ItemTemplate> <telerik:RadRating ID="RadRatingItem" runat="server" ItemCount="10" SelectionMode="Continuous" Precision="Half" Orientation="Horizontal" AutoPostBack="true" OnRate="RadRatingItem_Rate" /> </ItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView></telerik:RadGrid>Thanks!