locked
AJAX Rating Control in ListView using Database in ASP.net 4.0 RRS feed

  • Question

  • User1012377065 posted

    I want to use Star Rating Control in listview ..so that users can rate videos... and that rating should get stored into a database.

    If anyone can help me with that, i will be very thankful. 

    "If possible through LinqDataSource.....it will be great" :D

    Friday, May 8, 2015 1:50 AM

Answers

  • User1711366110 posted

    hi prabhavshukla,
      As per your case, the following code snippet which may help you to get the expected result :

    Listview with Ajax rating control

    <asp:ListView ID="lstvw1" runat="server" > <ItemTemplate> <fieldset> <cc1:Rating ID="Rating1" runat="server" CurrentRating='<%# Bind("VideoRating") %>' StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar" FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar" OnChanged="Rating1_Changed" ></cc1:Rating> </fieldset> </ItemTemplate> </asp:ListView>
    OnChange Event

    protected void Rating1_Changed(object sender, AjaxControlToolkit.RatingEventArgs e) { AjaxControlToolkit.Rating Rating1 = (AjaxControlToolkit.Rating)sender; string productId=;//get corresponding product id here string Rateid = e.value; updateRating(productId,Rateid); //Bind your corresponding datasource to list view here }
    Update corresponding value to database :

    private void updateRating(string ProductId, string Rating) { // put your values into parameters: SqlParameter paramRating = new SqlParameter("@Rating", Rating); SqlParameter paramProductId = new SQlParameter("@ProductId", ProductId); using(SqlCommand cmd = new SqlCommand( "UPDATE Products SET CustomerRating = @Rating WHERE Products.ProductID=@ProductId", new SqlConnection( ConfigurationManager.ConnectionStrings["db1"].ToString()))) { cmd.Parameters.Add(paramRating); cmd.Parameters.Add(paramProductId); cmd.Connection.Open(); cmd.ExecuteNonQuery(); } }

    --
    with regards,
    Edwin

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 11, 2015 10:40 PM