TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Pradeep kumar
NA
1
695
Working with rating control in ajax toolkit
Sep 15 2014 3:21 AM
I created a rating web application.Here is the code...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
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 this code creates new rows while user clicks on rating control...Plz make some changes that instead of creating rows each time it can update data in single row...Whereas RatingDetails is the name of sql table.Thanks
Reply
Answers (
0
)
how to bind crystal report in two tables,two SP,two datasets
Dictionary keys printing problem