问题描述
你好,
我已经在数据库中获得了诸如product_overall_rating,product_appearance_rating,product_quality_rating之类的字段,并且这些字段的values(rating)已插入数据库中.
我已经使用了gridview并在其中创建了
总体评分和5个单选按钮:
外观等级和5个单选按钮:
质量评级和5个单选按钮:
现在我已经从网格视图中读取了值,并根据数据库中的值(额定值)检查了单选按钮.
我唯一想做的就是使用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.
推荐答案
<script language="javascript" src="Scripts/jQuery1.7.js" type="text/javascript"></script>
<script type="text/javascript">
您将不得不使用jquery AJAX和asmx Web服务从数据库异步读取评级,然后在异步请求的成功事件处理程序上,根据评级值即时生成html.在上面的代码中,我将该值硬编码为"7",因此它会生成7星.我想这就是CP的工作方式(来源:FireBug)
但是,由于您使用的是GridView,并且该列很可能是模板列,因此尝试通过其ID访问该列/单元格会很棘手,因为直到列呈现后才会生成此类列的ID,因为该列只是一个模板在设计时不是真正的列(如果有意义).
我认为,如果您在服务器端执行此操作而不是依赖于jQuery,会更容易.您可以处理DataBound(我认为?)事件,并确定要显示多少个满星和多少个空星.
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.
这篇关于使用jquery进行只读明星评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!