Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
 
Add your own
alternative version

Rating Demystified: Ajax Way, Amazon Way*

, 16 Aug 2008
Ever wondered, how the amazon rating system works with multiple items in the same page, here is a simple article to describe the basic bare bones needed to create an asynchronous rating module using ASP.NET , SQL Server and ..... AJAX
Rating.zip
Rating
bin
Rating.dll
Rating.pdb
Global.asax
images
0.gif
0rating.gif
0star.gif
1.gif
1star.gif
2.gif
2star.gif
3.gif
3star.gif
4.gif
4star.gif
5.gif
5star.gif
ajax.jpg
morestars.jpg
morestars.psd
saved.gif
spacer.gif
stars0.gif
stars1.5.gif
stars1.gif
stars2.5.gif
stars2.gif
stars3.5.gif
stars3.gif
stars4.5.gif
stars4.gif
stars5.gif
Thumbs.db
Rating.csproj.webinfo
Rating.suo
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;


namespace Rating
{
	/// <summary>
	/// Summary description for Rate.
	/// </summary>
	public class Rate : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label lblRating;
		
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			string p = "Select * from " + ConfigurationSettings.AppSettings["MyPhotos"] + " WHERE id = '" + Convert.ToInt32(Request.QueryString["id"]) + "'";
				
			clsDataAccess myDAR = new clsDataAccess();
			myDAR.openConnection(); 
			double myRatedBy = Convert.ToInt32(myDAR.getValue(p,Convert.ToInt32(ConfigurationSettings.AppSettings["RatedByField"])));
			double myScore = Convert.ToDouble(myDAR.getValue(p,Convert.ToInt32(ConfigurationSettings.AppSettings["ScoreField"])));
				
			double myCRating = Convert.ToDouble(Request.QueryString["Rating"]);
			double myTotalRating = (myScore + myCRating)/(myRatedBy+1);
		
			myDAR.closeConnection();


			double ORating = 0.0;

			if (myRatedBy>0)
				ORating = myScore/myRatedBy;
			
			string myTotalRatingString = "";

			if ((ORating <1)&&(ORating>0))
				myTotalRatingString = ".5";
			else if (ORating ==1.0)
				myTotalRatingString = "1";
			else if ((ORating >1)&&(ORating<2))
				myTotalRatingString = "1.5";
			else if (ORating ==2.0)
				myTotalRatingString = "2";
			else if ((ORating >2)&&(ORating<3))
				myTotalRatingString = "2.5";
			else if (ORating ==3.0)
				myTotalRatingString = "3";
			else if ((ORating >3)&&(ORating<4))
				myTotalRatingString = "3.5";
			else if (ORating ==4.0)
				myTotalRatingString = "4";
			else if ((ORating >4)&&(ORating<5))
				myTotalRatingString = "4.5";
			else if (ORating ==5.0)
				myTotalRatingString = "5";
			else if (ORating ==0.0)
				myTotalRatingString = "0";


			lblRating.Text  = "<IMG src='images/stars" + myTotalRatingString + ".gif'>" ;
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.lblRating.Init += new System.EventHandler(this.lblRating_Init);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void lblRating_Init(object sender, System.EventArgs e)
		{
		
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author


| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 16 Aug 2008
Article Copyright 2006 by Raj Lal
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid