Click here to Skip to main content
11,928,786 members (58,571 online)
Rate this:
Please Sign up or sign in to vote.
See more: ASP.NET jQuery
Hello ,

i have got fields in database like product_overall_rating , product_ appearance_rating,product_quality_rating and these fields values(rating) are inserted in database.
I have taken a gridview and inside that created
overall rating and 5 radio buttons:
appearance rating and 5 radio buttons :
quality rating and 5 radio buttons:

Now i have read values from grid view and made radio buttons checked according to values(ratings) in database.
The only thing i want to do is to convert checked radio buttons to star images using jquery.
Posted 11-Oct-12 6:42am
Sergey Alexandrovich Kryukov 11-Oct-12 14:24pm
"Convert"? Hm. What curse on this site causes so many people to call everything "convert"? Whatever. Go ahead and do it; consider you got my approval.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Ok this is just a rough and oversimplified idea not the actual thing, I am leaving the full implementation as an exercise for you:

<script language="javascript" src="Scripts/jQuery1.7.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var html;
            for (i = 0; i < 7; i++) {
                html += "<img src="images/starfill.png" alt="rating" />";
<asp:Panel ID="ratingpanel" runat="server" ClientIDMode="Static">

You would have to read the ratings from the database asynchronously using jquery AJAX and an asmx web service and then on the success event handler of the async request, generate an html on the fly based on the rating value. In the above code i have hardcoded that value to be "7" so it generates 7 stars. I suppose that's how CP does (source: FireBug)

However, since you are using a GridView and the column is most likely a template column its going to be tricky trying to access that column/cell by its ID because ids for such columns are not generated until the page renders because the column is just a template not a real column at design time (if that makes sense).

I think it would be easier if you did this bit at the server side rather than depending on jquery. You can handle the DataBound (i think??) event and decide how many full stars and how many empty stars to show.
Aman.A 11-Oct-12 15:24pm
eh??? what did you change Ken?? :)
Marcus Kramer 11-Oct-12 15:45pm
He just changed your pre tag so that the code would render better on screen.
Aman.A 11-Oct-12 15:49pm
ah! cheers Marcus!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100