Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
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
Comments
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.
--SA

1 solution

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

HTML
<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" />";
            }

            $("#ratingpanel").html(html);
        });
    </script>
<asp:Panel ID="ratingpanel" runat="server" ClientIDMode="Static">
</asp:Panel>


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.
 
Share this answer
 
v3
Comments
I.explore.code 11-Oct-12 15:24pm    
eh??? what did you change Ken?? :)
fjdiewornncalwe 11-Oct-12 15:45pm    
He just changed your pre tag so that the code would render better on screen.
I.explore.code 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900