GridRatingColumn displays a RadRating control both in view and edit mode, giving your users the functionality to view or modify the rating of your data items. GridRatingColumn binds to your data source throuh its DataField property specifying the name of a numeric field from your data. The column supports automatic data source operations with ASP.NET data source controls. You can additionally customize the behavior of the rating controls using the following properties:
To retrieve or modify the value of the rating control in a given RadGrid item programmatically, you can use two options:
As the GridRatingColumn renders a RadRating control both in view and edit mode, the GridRatingColumnEditor is always initialized. This means that you can access the editor using:
GridEditableItem.EditManager.GetColumnEditor([ColumnUniqueName])
even when the item is not in edit mode, including when you want to access a modified rating value on postback with AllowRatingInViewMode = true.
Similary, GridEditableItem.ExtractValues(Hashtable values) will also return the modified rating value both in view and edit mode.
GridEditableItem.ExtractValues(Hashtable values)
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DefaultVB.aspx.vb" Inherits="Telerik.GridExamplesVBNET.GeneralFeatures.GridRatingColumn.DefaultVB" %><%@ Register TagPrefix="telerik" Namespace="Telerik.QuickStart" %><%@ Register TagPrefix="telerik" TagName="Header" Src="~/Common/Header.ascx" %><%@ Register TagPrefix="telerik" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %><%@ Register TagPrefix="telerik" TagName="Footer" Src="~/Common/Footer.ascx" %><%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %><%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <telerik:HeadTag runat="server" ID="Headtag2"></telerik:HeadTag> <!-- custom head section --> <!-- end of custom head section --> <style type="text/css"> .bigModuleBottom table td { padding: 1px 5px; } #ResultPanel b { color: Red; } </style></head><body class="BODY"> <form id="mainForm" runat="server"> <telerik:Header runat="server" ID="Header1" NavigationLanguage="VB" ShowDbResetTimer="true"> </telerik:Header> <telerik:RadScriptManager ID="ScriptManager1" runat="server"> </telerik:RadScriptManager> <!-- content start --> <telerik:ConfiguratorPanel ID="ConfiguratorPanel1" runat="server" Expanded="true"> <div class="title"> Configure GridRatingColumn: </div> <asp:Panel ID="ResultPanel" runat="server" Style="float: right; width: 250px"> </asp:Panel> <table> <tr> <td> ItemCount (MAX 10) </td> <td> <telerik:RadNumericTextBox ID="ItemCountBox" runat="server" Value="5" NumberFormat-AllowRounding="false" NumberFormat-DecimalDigits="0" Style="margin-left: 10px"> </telerik:RadNumericTextBox> </td> </tr> <tr> <td> SelectionMode </td> <td> <asp:RadioButtonList ID="SelectionModeList" runat="server" RepeatColumns="2"> <asp:ListItem Text="Single" Value="Single"></asp:ListItem> <asp:ListItem Text="Continuous" Value="Continuous" Selected="True"></asp:ListItem> </asp:RadioButtonList> </td> </tr> <tr> <td> Precision </td> <td> <asp:RadioButtonList ID="PrecisionList" runat="server" RepeatColumns="3"> <asp:ListItem Text="Exact" Value="Exact"></asp:ListItem> <asp:ListItem Text="Half" Value="Half"></asp:ListItem> <asp:ListItem Text="Item" Value="Item" Selected="True"></asp:ListItem> </asp:RadioButtonList> </td> </tr> <tr> <td> IsDirectionReversed </td> <td> <asp:RadioButtonList ID="ReversedList" runat="server" RepeatColumns="2"> <asp:ListItem Text="True" Value="True"></asp:ListItem> <asp:ListItem Text="False" Value="False" Selected="True"></asp:ListItem> </asp:RadioButtonList> </td> </tr> <tr> <td> AllowRatingInViewMode </td> <td> <asp:RadioButtonList ID="RateInViewModeList" runat="server" RepeatColumns="2"> <asp:ListItem Text="True" Value="True"></asp:ListItem> <asp:ListItem Text="False" Value="False" Selected="True"></asp:ListItem> </asp:RadioButtonList> </td> </tr> <tr> <td colspan="2"> <asp:Button ID="ApplyButton" runat="server" Text="Apply" Width="120px" OnClick="ApplyButton_Click" CssClass="button" /> </td> </tr> </table> </telerik:ConfiguratorPanel> <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadGrid1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> <telerik:AjaxUpdatedControl ControlID="ResultPanel" /> </UpdatedControls> </telerik:AjaxSetting> <telerik:AjaxSetting AjaxControlID="ApplyButton"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"> </telerik:RadAjaxLoadingPanel> <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" Width="700px" AllowSorting="true" AllowFilteringByColumn="true" AllowAutomaticUpdates="true" AllowAutomaticInserts="true" OnItemCommand="RadGrid1_ItemCommand" OnItemInserted="RadGrid1_ItemInserted" OnItemUpdated="RadGrid1_ItemUpdated" OnItemCreated="RadGrid1_ItemCreated"> <MasterTableView DataKeyNames="ID" CommandItemDisplay="Top" Width="100%"> <Columns> <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditColumn"> </telerik:GridEditCommandColumn> <telerik:GridBoundColumn DataField="ID" HeaderText="Rank" ReadOnly="true" Visible="false"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="Title" HeaderText="Title" FilterControlWidth="80%"> </telerik:GridBoundColumn> <telerik:GridRatingColumn DataField="Rating" HeaderText="Rating"> <HeaderStyle Width="250px" /> </telerik:GridRatingColumn> <telerik:GridButtonColumn ButtonType="PushButton" CommandName="UpdateRating" ButtonCssClass="button" Visible="false" UniqueName="UpdateColumn" Text="Update"> <HeaderStyle Width="50px" /> </telerik:GridButtonColumn> <telerik:GridNumericColumn DataField="Votes" HeaderText="Votes" FilterControlWidth="30px" DataType="System.Int32"> <HeaderStyle Width="80px" /> </telerik:GridNumericColumn> </Columns> </MasterTableView> </telerik:RadGrid> <asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>" SelectCommand="SELECT [ID], [Title], [Rating], [Votes] FROM [MovieRatings]" UpdateCommand="UPDATE [MovieRatings] SET [Title] = @Title, [Rating] = @Rating, [Votes] = @Votes WHERE [ID] = @ID" InsertCommand="INSERT INTO [MovieRatings] ([Title], [Rating], [Votes]) VALUES (@Title, @Rating, @Votes)"> <UpdateParameters> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="Rating" Type="Decimal" /> <asp:Parameter Name="Votes" Type="Int32" /> <asp:Parameter Name="ID" Type="Int32" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="Title" Type="String" /> <asp:Parameter Name="Rating" Type="Decimal" /> <asp:Parameter Name="Votes" Type="Int32" /> </InsertParameters> </asp:SqlDataSource> <!-- content end --> <telerik:Footer runat="server" ID="Footer1"></telerik:Footer> </form></body></html>
Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.
Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.
If you have any questions, do not hesitate to contact us at sales@telerik.com.