Welcome, Guest. Please login or register.
Did you miss your activation email?
Your Ad Here
Pages: [1]   Go Down
  Print  
Author Topic: Prefill the AJAX Control Toolkit Rating component with data from database  (Read 510 times)
0 Members and 1 Guest are viewing this topic.
HappyFace
Javaforums.net admin
Senior Member
*

Reputation: 16
Developer @ Engineeringserver network
Offline Offline
Posts: 2549
Referrals: 12
Activity
12%

WWW Awards
« on: August 02, 2009, 08:06:00 AM »

This is a stripped down version of a method i wrote to retrieve the score to the ASP.NET AJAX Control Toolkit Rating component from an ID. What it does is dynamically build the rating control and depending on the result of the database query i prefill the rating component.

      
Code
GeSHi (csharp):
  1.  public int selectStarRating(int ID)
  2.        {
  3.            string sqlQuery = "select score from someTable where scoreID = @scoreID";
  4.  
  5.            SqlCommand cmd = new SqlCommand(sqlQuery, conn);            
  6.            cmd.Parameters.Add("@scoreID", SqlDbType.Int);
  7.            cmd.Parameters["@scoreID"].Value = ID;
  8.  
  9.            try
  10.            {
  11.                conn.Open();
  12.                a = new SqlDataAdapter(cmd);
  13.                s = new DataSet();
  14.                a.Fill(s);
  15.                conn.Close();
  16.  
  17.                foreach (DataRow dr in s.Tables[0].Rows)
  18.                {
  19.                    this.Score = (int)dr["Score"];
  20.                }
  21.            }
  22.            catch (Exception e)
  23.            {
  24.                System.Diagnostics.Debug.Write(e.Message);
  25.            }
  26.            return (int)Score;
  27.        }
Created by GeSHI 1.0.7.20

To fill your rating control you need to call the method like this:

Code
GeSHi (csharp):
  1. r.CurrentRating = v.selectStarRating(10);
Created by GeSHI 1.0.7.20

screenshot
The screenshot belows demonstrates the code above but in my own version it also display the question, the amount of people that rated and the average rating at the right that are given by the x amount of people.



« Last Edit: August 02, 2009, 08:43:30 AM by HappyFace » Logged

It doesn't matter how hard you've studied; the material won't be on the exam anyway.
Admin @ www.Engineeringserver.com General Admin @ www.Javaforums.net and it's subsites Forum admin @ www.Javaforums.net Global moderator @ www.Engineeringserver.com network Java / .NET blogger @ www.Engineeringserver.com/blog
XMA performer since 2006 @ http://www.engineeringserver.com/XMA-NaN/ Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://www.javaforums.net...lery.html;sa=media;id=170
http://img222.imageshack....707/arkietomatoesmall.jpg
http://img208.imageshack.us/img208/7141/smalli.png
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
dotNETprogrammers.net/forum :: A community for .NET developers
« on: August 02, 2009, 08:06:00 AM »

 Logged
Pages: [1]   Go Up
  Print  
 
Jump to: