Wrox Programmer Forums
|
ASP.NET 4.5.1 General Discussion For ASP.NET 4.5.1 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4.5.1 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 14th, 2014, 01:22 PM
Registered User
 
Join Date: May 2014
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Working with rating control????

Hello Maters...I wanna to work with rating control in AjaxToolkit Liabrery. I searched on google and got some code.

Code:
public partial class Demo_Default : System.Web.UI.Page
{ SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CloudShopConnectionString1"].ConnectionString);
    
protected void RatingControlChanged(object sender, AjaxControlToolkit.RatingEventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into RatingDetails(Rate)values(@Rating)",con);
cmd.Parameters.AddWithValue("@Rating",Rating1.CurrentRating);
cmd.ExecuteNonQuery();
con.Close();
BindRatingControl();
}
protected void BindRatingControl()
{
    int total = 0;

    DataTable dt = new DataTable();
    con.Open();
    SqlCommand cmd = new SqlCommand("Select Rate from RatingDetails", con);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(dt);
    if (dt.Rows.Count > 0)
    {
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            total += Convert.ToInt32(dt.Rows[i][0].ToString());
        }
        int average = total / (dt.Rows.Count);
        Rating1.CurrentRating = average;

        Label1.Text = Convert.ToInt32(total).ToString();
       
        lbltxt.Text = dt.Rows.Count + "user(s) have rated this article";
    }
}
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
            {
                BindRatingControl();
            }
    }
As it working fine...but as i rate anything..It creates a new row in database and inserts rating values..
Please make some changes in the code that it updates the frist row instead of creating new row each time...Ihanks in advance





Similar Threads
Thread Thread Starter Forum Replies Last Post
Question on Rating items, etc. scottlucas58 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 December 31st, 2008 08:48 PM
Reset Article View Count and Rating retroviz BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 July 20th, 2008 10:43 AM
Rating &ViewCount do not increment tectrix BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 15 May 30th, 2007 06:46 AM
checkpassword control not working aruni_cbe ASP.NET 1.0 and 1.1 Professional 0 October 7th, 2006 05:56 AM
Working with MSHFlexGrid control predal VB How-To 0 March 3rd, 2004 07:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.