Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
0
Answer
Working with rating control in ajax toolkit
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Pradeep kumar
10y
471
1
Reply
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
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
how to bind crystal report in two tables,two SP,two datasets
Dictionary keys printing problem