Sharepoint 2010 Programmatically adding custom List view with rating column on page does'nt display the rating stars
-
mercoledì 2 maggio 2012 05:03
I am trying to create a new custom list view with rating column in it and adding that view on page as a list view webpart.
List view is getting added on the page but ratings stars are not visible on the page.
When I am editing the webpart from UI and modify the view and saving that view without doing any changes it starts showing the ratings starts.
Tutte le risposte
-
mercoledì 2 maggio 2012 06:56
-
mercoledì 2 maggio 2012 06:58Check this : http://www.sharemuch.com/2009/12/31/programaticaly-enable-rating-on-sharepoint-2010-lists/
get2pallav
Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you. -
mercoledì 2 maggio 2012 07:26No, I am using out of the box Rating column. I am just enabling the rating feature on list and adding list view webpart on my home page using the defualt view of the list which is having the rating field too.
-
mercoledì 2 maggio 2012 07:39
Hey,
This code will help work for you
private void averagerating(SPWeb web) { web.AllowUnsafeUpdates = true; SPList list1 = web.Lists["List Name"]; string averagerating = web.Fields.Add("Average Rating", SPFieldType.Calculated,false); SPFieldCalculated average = (SPFieldCalculated)web.Fields["Average Rating"]; string abc = average.InternalName; average.Formula = @"=[Rating (0-5)]"; average.OutputType = SPFieldType.Number; average.Update(); SPField field1 = web.AvailableFields["Average Rating"]; if (!list1.Fields.ContainsField("Average Rating")) { list1.Fields.Add(field1); } list1.Update(); SPView view1 = list1.DefaultView; view1.ViewFields.DeleteAll(); view1.ViewFields.Add("Rating (0-5)"); view1.ViewFields.Add("Average Rating"); web.Update(); web.AllowUnsafeUpdates = false; }Let me know if you have any queries :)
Mark as answer if it solves your problem :)
"The Only Way To Get Smarter Is By Playing A Smarter Opponent"
-
mercoledì 2 maggio 2012 08:22@Ravi , I am able to add rating column and can see them in default view of list. My main issue is that when I add a listview webpart programatically using default view of list on my home page , stars are not visible and user is not able to rate the content.
- Modificato AbhishekAgrawal mercoledì 2 maggio 2012 08:29

