5 starting
DESCRIPTION
Ejemplo de five StartingTRANSCRIPT
![Page 1: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/1.jpg)
INTRODUCTIONIn this post, I am explain how to Implement 5 star rating system in ASP.NET inside Gridview.
STEPS :STEP - 1 : CREATE NEW PROJECT.Go to File > New > Project > Select asp.net web forms application > Entry Application Name > Click OK.
STEP-2: ADD A DATABASE.Go to Solution Explorer > Right Click on App_Data folder > Add > New item > Select SQL Server Database Under Data > Enter Database name > Add.
STEP-3: CREATE 2 TABLE FOR SAVE/ FETCH DATA.Open Database > Right Click on Table > Add New Table > Add Columns > Save > Enter table name > Ok. In this example, I have used two tables as below Table1
Table2
STEP-4: ADD ENTITY DATA MODEL.Go to Solution Explorer > Right Click on Project name form Solution Explorer > Add > New item > Select ADO.net Entity Data Model under data > Enter model name > Add.A popup window will come (Entity Data Model Wizard) > Select Generate from database > Next >Chose your data connection > select your database > next > Select tables > enter Model Namespace > Finish.
STEP-5: ADD A CLASS.Right Click on Solution Explorer > Add > Class > Enter Class Name > Add. Here is the class.
1. namespace ASPRatingApp
2. {
3. public class ArticleWithScore
![Page 2: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/2.jpg)
4. {
5. public int ArticleID { get; set; }
6. public string ArticleTitle { get; set; }
7. public int Score { get; set; }
8. }
9. }
10.
STEP-6: ADD A WEBPAGE AND DESIGN FOR SHOW/SAVE RATING FROM/TO DATABASE.Go to Solution Explorer > Right Click on Project name form Solution Explorer > Add > New item > Select web form/ web form using master page under Web > Enter page name > Add.
JS Code
1. <script src="Scripts/jquery-1.7.1.js"></script>
2. <script language="javascript" type="text/javascript">
3. $(document).ready(function () {
4. $(".rating-star-
block .star").mouseleave(function () {
5. $("#" + $(this).parent().attr('id') +
" .star").each(function () {
6. $(this).addClass("outline");
7. $(this).removeClass("filled");
8. });
9. });
10. $(".rating-star-
block .star").mouseenter(function () {
11. var hoverVal = $(this).attr('rating');
12. $(this).prevUntil().addClass("filled");
13. $(this).addClass("filled");
14. $("#RAT").html(hoverVal);
15. });
16. $(".rating-star-block .star").click(function ()
{
17.
18. var v = $(this).attr('rating');
19. var newScore = 0;
![Page 3: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/3.jpg)
20. var updateP = "#" + $
(this).parent().attr('id') + ' .CurrentScore';
21. var artID = $("#" + $
(this).parent().attr('id') + ' .articleID').val();
22.
23. $("#" + $(this).parent().attr('id') +
" .star").hide();
24. $("#" + $(this).parent().attr('id') +
" .yourScore").html("Your Score is : <b style='color:#ff9900; font-
size:15px'>" + v + "</b>");
25. $.ajax({
26. type: "POST",
27. url: "Default.aspx/SaveRating",
28. data: "{articleID: '" + artID +
"',rate: '" + v + "'}",
29. contentType: "application/json;
charset=utf-8",
30. dataType: "json",
31. success: function (data) {
32. setNewScore(updateP, data.d);
33. },
34. error: function (data) {
35. alert(data.d);
36. }
37. });
38. });
39. });
40. function setNewScore(container, data) {
41. $(container).html(data);
42. $
("#myElem").show('1000').delay(2000).queue(function (n) {
43. $(this).hide(); n();
44. });
45. }
46. </script>
47.
![Page 4: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/4.jpg)
HTML Code
1. <style type="text/css">
2. .rating-star-block .star.outline {
3. background: url("images/star-empty-lg.png") no-repeat
scroll 0 0 rgba(0, 0, 0, 0);
4. }
5. .rating-star-block .star.filled {
6. background: url("images/star-fill-lg.png") no-repeat
scroll 0 0 rgba(0, 0, 0, 0);
7. }
8. .rating-star-block .star {
9. color:rgba(0,0,0,0);
10. display : inline-block;
11. height:24px;
12. overflow:hidden;
13. text-indent:-999em;
14. width:24px;
15. }
16. a {
17. color:#005782;
18. text-decoration:none;
19. }
20. </style>
21. <h3>Rating in ASP.NET</h3>
22. <div>
23. <asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="false" CellPadding="5">
24. <Columns>
25. <asp:BoundField HeaderText="Article ID"
DataField="ArticleID" />
26. <asp:BoundField HeaderText="Article Title"
DataField="ArticleTitle" />
27. <asp:TemplateField>
28. <ItemTemplate>
29. <div class="rating-star-block" id='div_<
%#Container.DataItemIndex %>'>
![Page 5: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/5.jpg)
30. <input type="hidden" class="articleID"
value='<%#Eval("ArticleID") %>' />
31. Current Score :<span
class="CurrentScore"><%#Eval("Score") %></span><br /><div
class="yourScore">Your Score : </div>
32. <a class="star outline" href="#"
rating="1" title="vote 1"> vote 1</a>
33. <a class="star outline" href="#"
rating="2" title="vote 2"> vote 2</a>
34. <a class="star outline" href="#"
rating="3" title="vote 3"> vote 3</a>
35. <a class="star outline" href="#"
rating="4" title="vote 4"> vote 4</a>
36. <a class="star outline" href="#"
rating="5" title="vote 5"> vote 5</a>
37. </div>
38. </ItemTemplate>
39. </asp:TemplateField>
40. </Columns>
41. </asp:GridView>
42. <div id="myElem" style="position:absolute; top:10px;
left:50%; display:none; background-color:yellow; padding:5px; border:1px
solid red">
43. Thank you for your rating!
44. </div>
45. </div>
46.
STEP-7: WRITE CODE IN PAGE_LOAD EVENT FOR FETCH DATA FROM DATABASE AND SHOW IN GRIDVIEW.
1.
2. protected void Page_Load(object sender, EventArgs e)
3. {
4. if (!IsPostBack)
5. {
6. PopulateArticle();
![Page 6: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/6.jpg)
7. }
8. }
9.
Here is the function...
1.
2. private void PopulateArticle()
3. {
4. using (MyDatabaseEntities dc = new
MyDatabaseEntities())
5. {
6. var v = (from a in dc.Articles
7. join b in dc.ArticleScores on
a.ArticleID equals b.ArticleID into bb
8. from b in bb.DefaultIfEmpty()
9. group new { a, b } by new
{ a.ArticleID, a.ArticleTitle } into AA
10. select new
11. {
12. AA.Key.ArticleID,
13. AA.Key.ArticleTitle,
14. Score = AA.Sum(a => a.b.Score) ==
null ? 0 : AA.Sum(a => a.b.Score),
15. Count = AA.Count()
16. });
17. List<ArticleWithScore> AWS = new
List<ArticleWithScore>();
18. foreach (var i in v)
19. {
20. AWS.Add(new ArticleWithScore
21. {
22. ArticleID = i.ArticleID,
23. ArticleTitle = i.ArticleTitle,
24. Score = i.Score/i.Count
25. });
26. GridView1.DataSource = AWS;
27. GridView1.DataBind();
![Page 7: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/7.jpg)
28. }
29. }
30. }
31.
STEP-8: WRITE CODE(FUNCTION) FOR SAVE USERS RATING INTO DATABASE WHICH IS CALLING FROM JQUERY. Import this 2 Namespace
1. using System.Web.Services;
2. using System.Web.Script.Services;
3.
1.
2. [WebMethod]
3. [ScriptMethod(ResponseFormat= ResponseFormat.Json)]
4. public static int SaveRating(int articleID, int rate)
5. {
6. int result = 0;
7. using (MyDatabaseEntities dc = new
MyDatabaseEntities())
8. {
9. dc.ArticleScores.Add(new ArticleScore
10. {
11. ArticleID = articleID,
12. ScoreID = 0,
13. Score = rate,
14. CreateDate = DateTime.Now
15. });
16. dc.SaveChanges();
17.
18. var newScore = (from a in dc.ArticleScores
19. where
a.ArticleID.Equals(articleID)
20. group a by a.ArticleID into aa
21. select new
![Page 8: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/8.jpg)
22. {
23. Score =
aa.Sum(a=>a.Score)/aa.Count()
24. }).FirstOrDefault();
25. result = newScore.Score;
26. }
27. return result;
28. }
29.
Glyphicons
Available glyphsIncludes over 250 glyphs in font format from the Glyphicon Halflings set. Glyphicons Halflings
are normally not available for free, but their creator has made them available for Bootstrap free
of cost. As a thank you, we only ask that you include a link back toGlyphicons whenever
possible.
glyphicon glyphicon-asterisk glyphicon glyphicon-plus glyphicon glyphicon-euro glyphicon glyphicon-eur
glyphicon glyphicon-minus glyphicon glyphicon-cloud
glyphicon glyphicon-envelope glyphicon glyphicon-pencil glyphicon glyphicon-glass glyphicon glyphicon-music glyphicon glyphicon-search glyphicon glyphicon-heart glyphicon glyphicon-star
glyphicon glyphicon-star-empty glyphicon glyphicon-user glyphicon glyphicon-film
glyphicon glyphicon-th-large glyphicon glyphicon-th
glyphicon glyphicon-th-list
![Page 9: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/9.jpg)
glyphicon glyphicon-ok glyphicon glyphicon-remove glyphicon glyphicon-zoom-in glyphicon glyphicon-zoom-out
glyphicon glyphicon-off glyphicon glyphicon-signal glyphicon glyphicon-cog glyphicon glyphicon-trash glyphicon glyphicon-home glyphicon glyphicon-file glyphicon glyphicon-time glyphicon glyphicon-road
glyphicon glyphicon-download-alt glyphicon glyphicon-download glyphicon glyphicon-upload glyphicon glyphicon-inbox
glyphicon glyphicon-play-circle glyphicon glyphicon-repeat glyphicon glyphicon-refresh glyphicon glyphicon-list-alt glyphicon glyphicon-lock glyphicon glyphicon-flag
glyphicon glyphicon-headphones glyphicon glyphicon-volume-off
glyphicon glyphicon-volume-down glyphicon glyphicon-volume-up glyphicon glyphicon-qrcode glyphicon glyphicon-barcode
glyphicon glyphicon-tag glyphicon glyphicon-tags glyphicon glyphicon-book
glyphicon glyphicon-bookmark glyphicon glyphicon-print
glyphicon glyphicon-camera glyphicon glyphicon-font glyphicon glyphicon-bold glyphicon glyphicon-italic
glyphicon glyphicon-text-height glyphicon glyphicon-text-width glyphicon glyphicon-align-left
glyphicon glyphicon-align-center glyphicon glyphicon-align-right glyphicon glyphicon-align-justify
glyphicon glyphicon-list glyphicon glyphicon-indent-left glyphicon glyphicon-indent-right
glyphicon glyphicon-facetime-video glyphicon glyphicon-picture
glyphicon glyphicon-map-marker glyphicon glyphicon-adjust glyphicon glyphicon-tint glyphicon glyphicon-edit
glyphicon glyphicon-share glyphicon glyphicon-check glyphicon glyphicon-move
glyphicon glyphicon-step-backward glyphicon glyphicon-fast-backward
glyphicon glyphicon-backward glyphicon glyphicon-play
![Page 10: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/10.jpg)
glyphicon glyphicon-pause glyphicon glyphicon-stop
glyphicon glyphicon-forward glyphicon glyphicon-fast-forward glyphicon glyphicon-step-forward
glyphicon glyphicon-eject glyphicon glyphicon-chevron-left glyphicon glyphicon-chevron-right
glyphicon glyphicon-plus-sign glyphicon glyphicon-minus-sign glyphicon glyphicon-remove-sign
glyphicon glyphicon-ok-sign glyphicon glyphicon-question-sign
glyphicon glyphicon-info-sign glyphicon glyphicon-screenshot
glyphicon glyphicon-remove-circle glyphicon glyphicon-ok-circle glyphicon glyphicon-ban-circle glyphicon glyphicon-arrow-left glyphicon glyphicon-arrow-right glyphicon glyphicon-arrow-up
glyphicon glyphicon-arrow-down glyphicon glyphicon-share-alt glyphicon glyphicon-resize-full
glyphicon glyphicon-resize-small glyphicon glyphicon-exclamation-sign
glyphicon glyphicon-gift glyphicon glyphicon-leaf glyphicon glyphicon-fire
glyphicon glyphicon-eye-open glyphicon glyphicon-eye-close
glyphicon glyphicon-warning-sign glyphicon glyphicon-plane
glyphicon glyphicon-calendar glyphicon glyphicon-random glyphicon glyphicon-comment glyphicon glyphicon-magnet
glyphicon glyphicon-chevron-up glyphicon glyphicon-chevron-down
glyphicon glyphicon-retweet glyphicon glyphicon-shopping-cart glyphicon glyphicon-folder-close glyphicon glyphicon-folder-open
glyphicon glyphicon-resize-vertical glyphicon glyphicon-resize-horizontal
glyphicon glyphicon-hdd glyphicon glyphicon-bullhorn
glyphicon glyphicon-bell glyphicon glyphicon-certificate glyphicon glyphicon-thumbs-up
glyphicon glyphicon-thumbs-down glyphicon glyphicon-hand-right glyphicon glyphicon-hand-left glyphicon glyphicon-hand-up
glyphicon glyphicon-hand-down glyphicon glyphicon-circle-arrow-right glyphicon glyphicon-circle-arrow-left glyphicon glyphicon-circle-arrow-up
glyphicon glyphicon-circle-arrow-down
![Page 11: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/11.jpg)
glyphicon glyphicon-globe glyphicon glyphicon-wrench glyphicon glyphicon-tasks glyphicon glyphicon-filter
glyphicon glyphicon-briefcase glyphicon glyphicon-fullscreen glyphicon glyphicon-dashboard glyphicon glyphicon-paperclip
glyphicon glyphicon-heart-empty glyphicon glyphicon-link
glyphicon glyphicon-phone glyphicon glyphicon-pushpin
glyphicon glyphicon-usd glyphicon glyphicon-gbp glyphicon glyphicon-sort
glyphicon glyphicon-sort-by-alphabet glyphicon glyphicon-sort-by-alphabet-alt
glyphicon glyphicon-sort-by-order glyphicon glyphicon-sort-by-order-alt glyphicon glyphicon-sort-by-attributes
glyphicon glyphicon-sort-by-attributes-alt glyphicon glyphicon-unchecked glyphicon glyphicon-expand
glyphicon glyphicon-collapse-down glyphicon glyphicon-collapse-up
glyphicon glyphicon-log-in glyphicon glyphicon-flash
glyphicon glyphicon-log-out glyphicon glyphicon-new-window
glyphicon glyphicon-record glyphicon glyphicon-save glyphicon glyphicon-open glyphicon glyphicon-saved glyphicon glyphicon-import glyphicon glyphicon-export glyphicon glyphicon-send
glyphicon glyphicon-floppy-disk glyphicon glyphicon-floppy-saved glyphicon glyphicon-floppy-remove glyphicon glyphicon-floppy-save glyphicon glyphicon-floppy-open glyphicon glyphicon-credit-card glyphicon glyphicon-transfer glyphicon glyphicon-cutlery glyphicon glyphicon-header
glyphicon glyphicon-compressed glyphicon glyphicon-earphone glyphicon glyphicon-phone-alt
glyphicon glyphicon-tower glyphicon glyphicon-stats
glyphicon glyphicon-sd-video glyphicon glyphicon-hd-video glyphicon glyphicon-subtitles
glyphicon glyphicon-sound-stereo glyphicon glyphicon-sound-dolby glyphicon glyphicon-sound-5-1 glyphicon glyphicon-sound-6-1 glyphicon glyphicon-sound-7-1
glyphicon glyphicon-copyright-mark
![Page 12: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/12.jpg)
glyphicon glyphicon-registration-mark glyphicon glyphicon-cloud-download glyphicon glyphicon-cloud-upload glyphicon glyphicon-tree-conifer
glyphicon glyphicon-tree-deciduous glyphicon glyphicon-cd
glyphicon glyphicon-save-file glyphicon glyphicon-open-file glyphicon glyphicon-level-up glyphicon glyphicon-copy glyphicon glyphicon-paste glyphicon glyphicon-alert
glyphicon glyphicon-equalizer glyphicon glyphicon-king
glyphicon glyphicon-queen glyphicon glyphicon-pawn glyphicon glyphicon-bishop glyphicon glyphicon-knight
glyphicon glyphicon-baby-formula glyphicon glyphicon-tent
glyphicon glyphicon-blackboard glyphicon glyphicon-bed glyphicon glyphicon-apple glyphicon glyphicon-erase
glyphicon glyphicon-hourglass glyphicon glyphicon-lamp
glyphicon glyphicon-duplicate glyphicon glyphicon-piggy-bank glyphicon glyphicon-scissors glyphicon glyphicon-bitcoin glyphicon glyphicon-btc glyphicon glyphicon-xbt glyphicon glyphicon-yen glyphicon glyphicon-jpy
glyphicon glyphicon-ruble glyphicon glyphicon-rub
glyphicon glyphicon-scale glyphicon glyphicon-ice-lolly
glyphicon glyphicon-ice-lolly-tasted glyphicon glyphicon-education
glyphicon glyphicon-option-horizontal glyphicon glyphicon-option-vertical
glyphicon glyphicon-menu-hamburger glyphicon glyphicon-modal-window
glyphicon glyphicon-oil glyphicon glyphicon-grain
glyphicon glyphicon-sunglasses glyphicon glyphicon-text-size glyphicon glyphicon-text-color
glyphicon glyphicon-text-background glyphicon glyphicon-object-align-top
glyphicon glyphicon-object-align-bottom glyphicon glyphicon-object-align-horizontal
glyphicon glyphicon-object-align-left glyphicon glyphicon-object-align-vertical glyphicon glyphicon-object-align-right
glyphicon glyphicon-triangle-right glyphicon glyphicon-triangle-left
glyphicon glyphicon-triangle-bottom
![Page 13: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/13.jpg)
glyphicon glyphicon-triangle-top glyphicon glyphicon-console
glyphicon glyphicon-superscript glyphicon glyphicon-subscript glyphicon glyphicon-menu-left glyphicon glyphicon-menu-right glyphicon glyphicon-menu-down glyphicon glyphicon-menu-up
How to use
![Page 14: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/14.jpg)
![Page 15: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/15.jpg)
![Page 16: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/16.jpg)
<div class="input-group input-group-lg"> <span class="input-group-addon" id="sizing-addon1">@</span> <input type="text" class="form-control" placeholder="Username" aria-describedby="sizing-addon1"> </div>
<div class="input-group"> <span class="input-group-addon" id="sizing-addon2">@</span> <input type="text" class="form-control" placeholder="Username" aria-describedby="sizing-addon2"> </div>
![Page 17: 5 Starting](https://reader036.vdocument.in/reader036/viewer/2022062407/563dbafb550346aa9aa94678/html5/thumbnails/17.jpg)