Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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 


cs
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";
        }

    }


im degab code but after da.Fill(dt); breakpoint out in method it is not going in if condition any solution please

aspx code

<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>


css
<%@ 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>
Posted
Updated 26-Feb-13 2:35am
v2

Hello Atul Rokade,
as you mentioned that control is not going to if condition so do you know that is data available in rating table
 
Share this answer
 
Comments
Atul Rokade 26-Feb-13 2:51am    
no sir data is blank in rating table
table structure is

Column Name Data Type Allow Nulls
Id Int(Set Identity=true) No


Rate int Yes

data insert in cs page only
i could not understand that what you do you want so please explain in detail what is your issue than i will try to help out you
 
Share this answer
 
Comments
Atul Rokade 26-Feb-13 3:26am    
my issue is when i run program its run bt rating control not rated so thats why im debug code so there im find breakpoint not going in if condition my question is how can i rate the rating control n how can i store them in database
follow these link or past your complete code aspx and .cs

http://imar.spaanjaars.com/410/building-a-simple-rating-control-for-aspnet-20[^]
 
Share this answer
 
v2
Comments
Atul Rokade 26-Feb-13 8:36am    
khalid sir im paste my full code please checkout
note: im using asp.net 2.0 ans ajax control 1.0

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