Style For Rating tool
{
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);
}
Rating Control
<asp:Rating ID="Rating1" runat="server"
CurrentRating="0" EmptyStarCssClass="emptyRatingStar"
FilledStarCssClass="filledRatingStar" OnChanged="Rating1_Changed" StarCssClass="ratingStar"
Style="float:left;" WaitingStarCssClass="savedRatingStar"
Tag='<%# Eval("fid") %>'>
</asp:Rating>
Images
Code
rotected void Rating1_Changed(object sender, AjaxControlToolkit.RatingEventArgs e)
{
//Rating code
string str = "insert into tbl_rate(r_p_id,r_rate) values(" + e.Tag + "," + e.Value + ")";
SqlCommand cmd = new SqlCommand(str, con);
cmd.ExecuteNonQuery();
//Fill Data List
string sel = "select * from tbl_image";
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(sel, con);
adp.Fill(dt);
dlstImage.DataSource = dt;
dlstImage.DataBind();
}
protected void dlstImage_ItemDataBound(object sender, DataListItemEventArgs e)
{
HiddenField h = (HiddenField)e.Item.FindControl("HiddenField1");
Rating re = (Rating)e.Item.FindControl("Rating1");
string sel = "select AVG(r_rate) as rating from tbl_rate where r_p_id=" + h.Value + "";
DataTable dt = new DataTable();
SqlDataAdapter adp = new SqlDataAdapter(sel, con);
adp.Fill(dt);
if (dt != null)
{
if (dt.Rows.Count > 0)
{
if (dt.Rows[0]["rating"] != DBNull.Value)
{
re.CurrentRating = Convert.ToInt32(dt.Rows[0]["rating"]);
}
}
}
}