iam using Rating control in my asp.net(2.0) application but it is not executed one error has come but im not getting how will i solve that error here im paste my cs code
protected void Page_Load(object sender, EventArgs e) { con = new SqlConnection("Data Source=ADMIN\\SQLEXPRESS;Initial Catalog=Example; Integrated Security=true"); if (!IsPostBack) { rating(); } } protected void RatingControlChanged(object sender, AjaxControlToolkit.RatingEventArgs e) { con.Open(); cmd = new SqlCommand("insert into Rating_Details(Rate)values(@Rating)", con); cmd.Parameters.AddWithValue("@Rating", ratingControl.CurrentRating); cmd.ExecuteNonQuery(); con.Close(); rating(); Response.Write("thank you for ur rating"); } protected void rating() { int total = 0; DataTable dt = new DataTable(); con.Open(); SqlCommand cmd = new SqlCommand("Select Rate from Rating_Details", con); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); if (dt.Rows.Count>0)//breakpoint not enter in if condition { for (int i = 0; i<dt.Rows.Count; i++) { total += Convert.ToInt32(dt.Rows[i][0].ToString()); } int average = total / (dt.Rows.Count); ratingControl.CurrentRating = average; lbltxt.Text = dt.Rows.Count + "user(s) have rated this article"; } }
<pre lang="xml"><body> <form id="form1" runat="server"> <%--<ajax:ToolkitScriptManager ID="ScripManager1" runat="server"/> --%><div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="pnlRating" runat="server"> <ContentTemplate> <table width="35%"> <tr> <td width="27%"> <b>Average Rating:</b> </td> <td> <ajaxToolkit:Rating ID="ratingControl" CurrentRating="0" MaxRating="5" RatingAlign="Horizontal" AutoPostBack="true" OnChanged="RatingControlChanged" runat="server" StarCssClass="ratingStar" WaitingStarCssClass="ratingSaved" EmptyStarCssClass="ratingEmpty" FilledStarCssClass="ratingFilled" > </ajaxToolkit:Rating> <b> <asp:label ID="lbltxt" runat="server"/> </b> </td> </tr> </table> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %> <!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 id="Head1" runat="server"> <title>Ajax Rating Sample</title> <style type="text/css"> .ratingStar { font-size: 0pt; width: 12px; height: 12px; cursor: pointer; background-repeat: no-repeat; display: block; } .ratingEmpty { background-image: url(ratingStarEmpty.gif); width:18px; height:18px; } .ratingFilled { background-image: url(ratingStarFilled.gif); width:18px; height:18px; } .ratingSaved { background-image: url(ratingStarSaved.gif); width:18px; height:18px; } </style> </head>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)