rebind the label's reader after rating changed

Last post 12-04-2008 12:50 PM by elephantman. 7 replies.

Sort Posts:

  • rebind the label's reader after rating changed

    11-30-2008, 9:26 AM
    • Member
      108 point Member
    • elephantman
    • Member since 06-27-2008, 4:33 PM
    • Posts 372

    hi

    i am using ajaxrating control. and i have a label to show the average of points for that item.

    I want from that label change after someone's vote is changed. I dont wanto to refresh or pass to another page and come back to that page. I want ot see the changing immediately on that page.

     How could i do that?

    here is my code on the page load inside the (!IsPostBack) control

     

     string id = Request.QueryString["id"];
                SqlConnection conx = new SqlConnection(strConnString);
                conx.Open();
                SqlCommand sorgu1a = new SqlCommand();
                sorgu1a.Connection = conx;
                sorgu1a.CommandText = "select AVG(K.puan) as ort from Kisi_Film_Puan K where K.film=@id";
                sorgu1a.Parameters.AddWithValue("@id", id);
                SqlDataReader drs = sorgu1a.ExecuteReader();
                if (drs.Read())
    
                    lblOrt.Text = drs["ort"].ToString();
    
                else
                    lblOrt.Text = "0";
                conx.Close();

    where should i put this code to exeute as i want ? ( Note: it must be shown at the first opening of the page )

  • Re: rebind the label's reader after rating changed

    11-30-2008, 10:41 AM
    • Contributor
      2,659 point Contributor
    • tehremo
    • Member since 03-15-2008, 1:03 AM
    • Richmond, VA
    • Posts 414

    You could wrap your rating control and your label in an updatepanel.  That way when the "OnChanged" event fires just those areas get updated.

    "Sector clear"
  • Re: rebind the label's reader after rating changed

    11-30-2008, 11:25 AM
    • Member
      108 point Member
    • elephantman
    • Member since 06-27-2008, 4:33 PM
    • Posts 372

    i put updatepanel like this:

     

     <asp:Panel ID="Panel1" runat="server" Visible="False" Height="50px" Width="125px" Font-Names="Arial" Font-Size="Medium">
                        Vote:
                        <ajax:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <cc1:Rating ID="Rating1" runat="server" CurrentRating="0" MaxRating="10"
                            StarCssClass="ratingStar" 
                            WaitingStarCssClass="savedRatingStar"
                            FilledStarCssClass="filledRatingStar" 
                            EmptyStarCssClass="emptyRatingStar" 
                            OnChanged="Rating_Changed"
                            AutoPostBack="True" Height="53px" Width="290px" BehaviorID="Rating1_RatingExtender">
                            </cc1:Rating>
                           (Ort: <asp:Label ID="lblOrt" runat="server" Text="Label"></asp:Label>/10)
                           </ContentTemplate>
                        </ajax:UpdatePanel>
                    </asp:Panel>

     

    but nothing is changed. Should i put anything else in the OnChanged event of AjaxRating to rebind my query and update the label's result ?

  • Re: rebind the label's reader after rating changed

    11-30-2008, 9:37 PM
    • Contributor
      2,659 point Contributor
    • tehremo
    • Member since 03-15-2008, 1:03 AM
    • Richmond, VA
    • Posts 414

    Can you post the code you are using in your onchanged event handler?

    "Sector clear"
  • Re: rebind the label's reader after rating changed

    12-01-2008, 1:30 PM
    • Member
      108 point Member
    • elephantman
    • Member since 06-27-2008, 4:33 PM
    • Posts 372

    here is the code in my ajax rating's onchanged event :

     

    protected void Rating_Changed(object sender, AjaxControlToolkit.RatingEventArgs e) 
        {
            string id = Request.QueryString["id"];
                SqlConnection con41 = new SqlConnection(strConnString);
                SqlCommand sorgu1v = new SqlCommand("Select * from Kisi_Film_Puan where kisi=@kisi and film=@film", con41);
                sorgu1v.Parameters.AddWithValue("@kisi", (int)Session["adi"]);
                sorgu1v.Parameters.AddWithValue("@film", id);
                con41.Open();
    
                SqlDataReader dr = sorgu1v.ExecuteReader();
                if (dr.Read())
                {
                    int rating = Convert.ToInt32(e.Value);
                    SqlConnection con4 = new SqlConnection(strConnString);
                    SqlCommand sorgu1c = new SqlCommand();
                    sorgu1c.Connection = con4;
                    sorgu1c.CommandType = CommandType.StoredProcedure;
                    sorgu1c.CommandText = "sp_UpdateKisiFilmPuan";
                    sorgu1c.Parameters.AddWithValue("puan", rating);
                    sorgu1c.Parameters.AddWithValue("user", (int)Session["adi"]);
                    sorgu1c.Parameters.AddWithValue("film1", id);
                    con4.Open();
                    sorgu1c.ExecuteNonQuery();
                    con4.Close();
    
                    
                }
                else
                {
                    int rating = Convert.ToInt32(e.Value);
                    SqlConnection con4 = new SqlConnection(strConnString);
                    SqlCommand sorgu = new SqlCommand();
                    sorgu.Connection = con4;
                    sorgu.CommandType = CommandType.StoredProcedure;
                    sorgu.CommandText = "sp_Izlenenler";
    
                    sorgu.Parameters.AddWithValue("kisi", (int)Session["adi"]);
                    sorgu.Parameters.AddWithValue("film", id);
                    sorgu.Parameters.AddWithValue("puan", rating);
    
                    con4.Open();
                    sorgu.ExecuteNonQuery();
                    con4.Close();
    
                }
        }

     

    as you see there is nothing about rebind the datasource of label. I am wondering about should i put something, and if yes what will be the code of that rebind ? just Datalist1.Databind() ? is it enough? , or shouldnt i ?

  • Re: rebind the label's reader after rating changed

    12-01-2008, 6:44 PM
    Answer
    • Contributor
      2,659 point Contributor
    • tehremo
    • Member since 03-15-2008, 1:03 AM
    • Richmond, VA
    • Posts 414

    You need to set the text of your label in this event handler (lblOrt.Text = "something";).  I'm guessing you'll set it to an int that is being returned from your DB query?

    "Sector clear"
  • Re: rebind the label's reader after rating changed

    12-04-2008, 12:42 PM
    • Member
      108 point Member
    • elephantman
    • Member since 06-27-2008, 4:33 PM
    • Posts 372

    first i am very sorry to answer lately. I had some school works so i look your answer now.

    my result will be a decimal number like 8,65.

    if i dont understand wrongly, you say the only way is put the code

    string id = Request.QueryString["id"];
                SqlConnection conx = new SqlConnection(strConnString);
                conx.Open();
                SqlCommand sorgu1a = new SqlCommand();
                sorgu1a.Connection = conx;
                sorgu1a.CommandText = "select AVG(K.puan) as ort from Kisi_Film_Puan K where K.film=@id";
                sorgu1a.Parameters.AddWithValue("@id", id);
                SqlDataReader drs = sorgu1a.ExecuteReader();
                if (drs.Read())

                    lblOrt.Text = drs["ort"].ToString();

                else
                    lblOrt.Text = "0";
                conx.Close();

     

    in onchanged event. Am i wrong?

  • Re: rebind the label's reader after rating changed

    12-04-2008, 12:50 PM
    • Member
      108 point Member
    • elephantman
    • Member since 06-27-2008, 4:33 PM
    • Posts 372

    after i put that code block to the onchanged event it works as i want. BUT i expect to solve this problem with LESS code, is it possible too? HOW?

Page 1 of 1 (8 items)