Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 25-Feb-13 21:29pm
Edited 26-Feb-13 3:35am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
Atul Rokade at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
Atul Rokade at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

follow these link or past your complete code aspx and .cs
 
http://imar.spaanjaars.com/410/building-a-simple-rating-control-for-aspnet-20[^]
  Permalink  
v2
Comments
Atul Rokade at 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)

  Print Answers RSS
0 OriginalGriff 274
1 Shweta N Mishra 216
2 PIEBALDconsult 210
3 Sergey Alexandrovich Kryukov 185
4 BillWoodruff 174
0 OriginalGriff 7,620
1 Sergey Alexandrovich Kryukov 6,937
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,495


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100