How to use Ajax Rating Control in listview?


I am using the AJAX Rating Control inside a ListView control, When I run the page it throws the error 'Specified cast is not valid'

Here Is the code 

(SELECT[prod].[prod_id],[prod].[prod_name],AVG([rates].[prod_rating]) AS[prod_rating] FROM [p1_shop] [pd] LEFT JOIN[prod_rating] [rate] ON [prod].[prod_id] = [rate].[prod_id];

 .aspx Code

<asp:ListView ID="product_list" runat="server" EnableTheming="False">
<ItemTemplate>

<cc1:Rating ID="Rating1" runat="server" currentrating='<%#Eval("rest_rating")%>' OnChanged="Rating1_Changed"
                            StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
                            FilledStarCssClass="FilledStar">
                            </cc1:Rating>

</ItemTemplate>
</asp:ListView>

Asked by:- RameshwarLate
0
: 149 At:- 9/10/2017 11:12:38 AM
c# asp-net ajax-rating-control listview

are you getting any value in Eval("rest_rating")? Check it and paste the values also, I think you are not getting Correct values in it 0
By : vikas_jk - at :- 9/10/2017 12:14:47 PM
yes, i getting the correct value, if i use with label its shows me correct average value. 0
By : RameshwarLate - at :- 9/11/2017 8:03:31 AM
Thanks for reply, When i use right join rating control working fine, but here shows only those records there have a rating value in rating table. 0
By : RameshwarLate - at :- 9/12/2017 6:54:35 AM





1 Answers
profileImage Answered by:- bhanu

Can you try implementing Math.Floor in your code with prod_rating because in your SQL query line you are taking data as prod_rating, check this line

AVG([rates].[prod_rating]) AS[prod_rating]

So try this code, if your value is not null and you are getting some Float Value

CurrentRating='<%# Math.Floor(Eval("prod_rating")) %>'

Or if that doesn't work check this link

https://www.aspsnippets.com/Articles/Using-ASPNet-AJAX-Rating-Control-inside-GridView-TemplateField-ItemTemplate.aspx

In the above link there is a post for Ajax Rating in Grid View(not in list view but it may help)

0
At:- 9/11/2017 1:55:57 PM Updated at:- 9/11/2017 2:00:51 PM





Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use