Click here to Skip to main content
15,885,132 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
/* The following styles are for the Rating */
.ratingStar {
font-size: 0pt;
width: 13px;
height: 12px;
margin: 0px;
padding: 0px;
cursor: pointer;
display: block;
background-repeat: no-repeat;
}

.filledRatingStar {
background-image: url(Images/FilledStar.png);
}

.emptyRatingStar {
background-image: url(Images/EmptyStar.png);
}

.savedRatingStar {
background-image: url(Images/SavedStar.png);
}
/******************************************/

</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">



<asp:Repeater ID="Repeater1" runat="server">
<itemtemplate>
 


<%#Container.ItemIndex+1 %>
<asp:Label ID="rvid" runat="server" Text='<%#Eval("rvid") %>'>
  <%#Eval("title") %>  <ajaxToolkit:Rating ID="Rating1" runat="server"
AutoPostBack="true" CurrentRating='<%# Eval("rating") %>' StarCssClass="ratingStar"
WaitingStarCssClass="savedRatingStar" FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar"
önChanged="Rating1_Changed">



</form>
</body>
</html>



using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;



public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["dsn_SQL"].ToString());
SqlCommand cmd = new SqlCommand();
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
ShowData();
}

private void ShowData()
{
con.Open();
cmd.Connection = con;
cmd.CommandText = "select * from product_reviews";
cmd.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Repeater1.DataSource = dt;
Repeater1.DataBind();
}
con.Close();
}

protected void Rating1_Changed(object sender, AjaxControlToolkit.RatingEventArgs e)
{
AjaxControlToolkit.Rating myRating = (AjaxControlToolkit.Rating)sender;
Label rvid = ((Control)sender).Parent.FindControl("rvid") as Label;
Response.Write(rvid.Text);
Response.Write(e.Value.ToString());


}
}
Posted
Comments
taha bahraminezhad Jooneghani 2-Jun-12 7:00am    
and were is your question?
Member 14209106 10-Apr-19 5:16am    
Hello, I've similar challenge. I want the repeater to display rating of each product from the database also, I'm in need of a solution, thanks

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