I have a radrating control in a radgrid to evaluate a series of questions. In that series of questions are Yes/No questions and those that have at least 3 options for evaluation values. My question: Is there a way to change the set of evaluation items in the radrating control based on whether the question is a Yes/No question or the other type? I have a column in the radgrid that indicates the question type. I also added two separate items in the radrating control with different numbers of rating items. One set to Yes/No and the other with the other set of selections. Is there a way to make change the visible property of one of these items to false when the radgrid is populated based on the question type?
7 Answers, 1 is accepted
0
Hello John,
You can use the server-side API of the RadRating control in order to modify its items. Please check the following example:
On the code-behind the Items collection can be accessed and items could be added, removed or modified as shown below:
Regards,
Slav
Telerik
You can use the server-side API of the RadRating control in order to modify its items. Please check the following example:
<
telerik:RadRating
ID
=
"radRating1"
runat
=
"server"
>
<
Items
>
<
telerik:RadRatingItem
Value
=
"1"
ToolTip
=
"Low"
></
telerik:RadRatingItem
>
<
telerik:RadRatingItem
Value
=
"2"
ToolTip
=
"Medium"
></
telerik:RadRatingItem
>
<
telerik:RadRatingItem
Value
=
"3"
ToolTip
=
"High"
></
telerik:RadRatingItem
>
</
Items
>
</
telerik:RadRating
>
On the code-behind the Items collection can be accessed and items could be added, removed or modified as shown below:
public
void
Page_Load(
object
sender, System.EventArgs e)
{
radRating1.Items.RemoveAt(2);
radRating1.Items[0].ToolTip =
"Yes"
;
radRating1.Items[1].ToolTip =
"No"
;
}
Regards,
Slav
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
John
Top achievements
Rank 1
answered on 15 Oct 2013, 02:05 PM
Slav,
Thanks for the reply. I need to change the radrating based on a column in the radgrid. I've tried on databind but that doesn't seem to work. What radgrid event do I need to use to be able to read the column and change the radrating control for that row?
Thanks,
John
Thanks for the reply. I need to change the radrating based on a column in the radgrid. I've tried on databind but that doesn't seem to work. What radgrid event do I need to use to be able to read the column and change the radrating control for that row?
Thanks,
John
0
John
Top achievements
Rank 1
answered on 15 Oct 2013, 03:22 PM
Dim item As GridDataItem
For Each item In Me.rgInputQuestions.Items
If item("RatingScaleGroup").Text = "1" Then
Me.rgInputQuestions.Controls("RatingValue").Visible = True
Me.rgInputQuestions.Controls("Yes_NoRating").Visible = False
Else
Me.rgInputQuestions.Controls("RatingValue").Visible = False
Me.rgInputQuestions.Controls("Yes_NoRating").Visible = True
End If
Next
0
John
Top achievements
Rank 1
answered on 15 Oct 2013, 03:29 PM
Dim item As GridDataItem
Dim RatingValue As RadRating = Me.rgInputQuestions.FindControl("RatingValue")
Dim Yes_NoRating As RadRating = Me.rgInputQuestions.FindControl("Yes_NoRating")
For Each item In Me.rgInputQuestions.Items
If item("RatingScaleGroup").Text = "1" Then
RatingValue.Visible = True
Yes_NoRating.Visible = False
Else
RatingValue.Visible = False
Yes_NoRating.Visible = True
End If
Next
<
telerik:GridTemplateColumn
HeaderText
=
"Rate Question"
UniqueName
=
"RatingScaleID"
Readonly
=
"true"
HeaderStyle-Width
=
"1%"
ItemStyle-Width
=
"1%"
>
<
ItemTemplate
>
<
telerik:RadRating
ID
=
"RatingValue"
runat
=
"server"
AutoPostBack
=
"true"
DataMember
=
"RatingScaleID"
ViewStateMode
=
"Enabled"
SelectionMode
=
"Single"
ItemCount
=
"3"
Value='<%# Eval("RatingScaleID")%>'
OnRate="RateValue_Rate"
Precision="Item"
ItemHeight = "32px"
ItemWidth = "32px"
>
<
Items
>
<
telerik:RadRatingItem
Value
=
"4"
HoveredImageUrl
=
"../../Images/NR_red.png"
HoveredSelectedImageUrl
=
"../../Images/NR_red.png"
SelectedImageUrl
=
"../../Images/NR_red.png"
ImageUrl
=
"../../Images/NR_black.png"
ToolTip
=
"Not Rated"
></
telerik:RadRatingItem
>
<
telerik:RadRatingItem
Value
=
"1"
HoveredImageUrl
=
"../../Images/Red_arrow_down_26x32.png"
HoveredSelectedImageUrl
=
"../../Images/black_arrow_down_26x32.png"
SelectedImageUrl
=
"../../Images/Red_arrow_down_26x32.png"
ImageUrl
=
"../../Images/Black_arrow_down_26x32.png"
ToolTip
=
"Doesn't Meet/No"
></
telerik:RadRatingItem
>
<
telerik:RadRatingItem
Value
=
"2"
HoveredImageUrl
=
"../../Images/Gold_arrow_left-right_32x32.png"
HoveredSelectedImageUrl
=
"../../Images/Gold_arrow_left-right_32x32.png"
SelectedImageUrl
=
"../../Images/Gold_arrow_left-right_32x32.png"
ImageUrl
=
"../../Images/Black_arrow_side-to-side.png"
ToolTip
=
"Meets/Yes"
>
</
telerik:RadRatingItem
>
<
telerik:RadRatingItem
Value
=
"3"
HoveredImageUrl
=
"../../Images/Green_arrow_up_26x32.png"
HoveredSelectedImageUrl
=
"../../Images/Green_arrow_up_26x32.png"
SelectedImageUrl
=
"../../Images/Green_arrow_up_26x32.png"
ImageUrl
=
"../../Images/Black_arrow_up_26x32.png"
ToolTip
=
"Exceeds"
>
</
telerik:RadRatingItem
>
</
Items
>
</
telerik:RadRating
>
<
telerik:RadRating
ID
=
"Yes_NoRating"
runat
=
"server"
AutoPostBack
=
"true"
DataMember
=
"RatingScaleID"
ViewStateMode
=
"Enabled"
SelectionMode
=
"Single"
ItemCount
=
"3"
Value='<%# Eval("RatingScaleID")%>'
OnRate="RateValue_Rate"
Precision="Item"
ItemHeight = "32px"
ItemWidth = "32px"
Visible = "false">
<
Items
>
<
telerik:RadRatingItem
Value
=
"4"
HoveredImageUrl
=
"../../Images/NR_red.png"
HoveredSelectedImageUrl
=
"../../Images/NR_red.png"
SelectedImageUrl
=
"../../Images/NR_red.png"
ImageUrl
=
"../../Images/NR_black.png"
ToolTip
=
"Not Rated"
></
telerik:RadRatingItem
>
<
telerik:RadRatingItem
Value
=
"1"
HoveredImageUrl
=
"../../Images/Red_arrow_down_26x32.png"
HoveredSelectedImageUrl
=
"../../Images/Red_arrow_down_26x32.png"
SelectedImageUrl
=
"../../Images/Red_arrow_down_26x32.png"
ImageUrl
=
"../../Images/Black_arrow_down_26x32.png"
ToolTip
=
"Doesn't Meet/No"
></
telerik:RadRatingItem
>
<
telerik:RadRatingItem
Value
=
"3"
HoveredImageUrl
=
"../../Images/Green_arrow_up_26x32.png"
HoveredSelectedImageUrl
=
"../../Images/Green_arrow_up_26x32.png"
SelectedImageUrl
=
"../../Images/Green_arrow_up_26x32.png"
ImageUrl
=
"../../Images/Black_arrow_up_26x32.png"
ToolTip
=
"Exceeds"
>
</
telerik:RadRatingItem
>
</
Items
>
</
telerik:RadRating
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
0
Accepted
Hello John,
You can find attached a sample page that should help you implement the desired functionality. It uses the ItemDataBound event of RadGrid in order to access the RadRating controls in each item and configure the accordingly.
Please use the example as a reference for your further development.
Regards,
Slav
Telerik
You can find attached a sample page that should help you implement the desired functionality. It uses the ItemDataBound event of RadGrid in order to access the RadRating controls in each item and configure the accordingly.
Please use the example as a reference for your further development.
Regards,
Slav
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
John
Top achievements
Rank 1
answered on 29 Oct 2013, 04:10 PM
Thanks for the reply. I get the following error.
Script control 'YesNoRating' is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors().
I did some searching earlier on this error when I tried to use the OnItemDataBound and found some posts indicating that it was only possible to hide a control during the pre-render event of the rad grid. I had put the code in the pre-render event and after the initial page load it works fine. It doesn't work on the initial page load though. Only after an item is selected in the grid above that causes the rsInputQuestions grid to reload. I have tried putting a rebind for the rsInputQuestions grid in various places in the code behind to no avail. Any ideas?
Edit: Here's the post I was talking about. http://nwije.blogspot.com/2011/04/script-control-controlname-is-not.html
Script control 'YesNoRating' is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors().
Parameter name: scriptControl
I did some searching earlier on this error when I tried to use the OnItemDataBound and found some posts indicating that it was only possible to hide a control during the pre-render event of the rad grid. I had put the code in the pre-render event and after the initial page load it works fine. It doesn't work on the initial page load though. Only after an item is selected in the grid above that causes the rsInputQuestions grid to reload. I have tried putting a rebind for the rsInputQuestions grid in various places in the code behind to no avail. Any ideas?
Edit: Here's the post I was talking about. http://nwije.blogspot.com/2011/04/script-control-controlname-is-not.html
0
John
Top achievements
Rank 1
answered on 29 Oct 2013, 06:06 PM
Ok I fixed the issue. I added code to register the controls which worked fine in when the control was in the pre-render event, but threw and error when in postback. Adding a line of code to check for post back and bypassing the registration steps at that point cleared up the issue.
Thanks again for your help.
Thanks again for your help.