auto postbak rate value to template grid

7 posts, 0 answers
  1. Mohamad
    Mohamad avatar
    15 posts
    Member since:
    Feb 2012

    Posted 25 Feb 2012 Link to this post

    not in
    protected
    void Button1_Click(object sender, EventArgs e)
    {
      foreach (GridViewRow row in GridView1.Rows)
      {
        RadRating ratg = (RadRating)row.FindControl("RadRating1");
      }
    }
    -------------

    me auto postbak rate value to grid ?
    rate value for template gird
    on postbak save to database
  2. Mohamad
    Mohamad avatar
    15 posts
    Member since:
    Feb 2012

    Posted 26 Feb 2012 Link to this post

    help me
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mohamad
    Mohamad avatar
    15 posts
    Member since:
    Feb 2012

    Posted 26 Feb 2012 Link to this post

    How do I correct this code?


    <asp:GridView ID="GridView1" runat="server"
            AutoGenerateColumns="False" ShowHeader="False" BorderStyle="None"
            GridLines="None" Width="100%" onrowcommand="GridView1_RowCommand">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:Button ID="Button1" runat="server" CommandArgument='<%# Eval("TopicID")%>' CommandName="Clik" Text="oki" />
    <telerik:RadRating ID="RadRating1" Runat="server" SelectionMode="Single" Skin="Windows7" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    ---------------
       public static string id;

        protected void tet(object sender, EventArgs e)
        {
            
            foreach (GridViewRow rw in GridView1.Rows)
            {
                RadRating r = (RadRating)rw.FindControl("RadRating1");
                id = r.Value.ToString();
            }

            Response.Write(id);

        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            if (e.CommandName == "Clik")
            {
                tet(null, null);
            }
        }

  5. Mohamad
    Mohamad avatar
    15 posts
    Member since:
    Feb 2012

    Posted 28 Feb 2012 Link to this post

     protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string val, postid;

            if (e.CommandName == "Clik")
            {
                GridViewRow row = (GridViewRow)(((Button)e.CommandSource).NamingContainer);

                postid = e.CommandArgument.ToString();

                Coments_Rate rt = new Coments_Rate();
                rt.PostID = Int32.Parse(postid);
                rt.UserName = User.Identity.Name;
                rt.ChekRateID();

                if (rt.Rate == false)
                {
                    RadRating rd = (RadRating)row.FindControl("RadRating1");
                    val = rd.Value.ToString();

                    rt.UserName = User.Identity.Name;
                    rt.Date = Time_Date.GetFarsiDate(DateTime.Now, false).Trim();
                    rt.Rating = Int32.Parse(val);
                    rt.TopikID = Int32.Parse(postid);
                    rt.Add_Raet();

                    Fakhravary.Message.MessageBox(val.ToString() + "   " + "امتیاز شما برای این مطلب" + "  " + User.Identity.Name + "  " + "کاربر گرامی", this);
                }
                else
                {
                    Fakhravary.Message.MessageBox("شما در امتیاز دهی این مطلب شرکت کرده اید", this);
                }     
            }
        }
  6. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 29 Feb 2012 Link to this post

    Hello Mohamad,

    Note that you don't need to handle the GridView's RowCommand event in order to reference the rating control. If you set the AutoPostBack property of RadRating to true, the control will initiate postback when you click any of its items and you will be able to handle its server-side event Rate. In the handler of this event you can get the value of the clicked RadRating and you can update the database accordingly.

    Page
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowHeader="False"
        BorderStyle="None" GridLines="None" Width="100%">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <telerik:RadRating ID="RadRating1" runat="server" SelectionMode="Single" AutoPostBack="true" OnRate="RadRating1_Rate" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

    Code-behind
    protected void RadRating1_Rate(object sender, EventArgs e)
    {
        RadRating rating = (RadRating)sender;
        Response.Write("You voted with " + rating.Value); // here you can update the database with the new value
    }

    The online demo Rating / RadRating in RadGrid shows the overall approach for achieving the desired functionality. It can be used as the implemented scenario is quite similar to your case.

    I would suggest creating separate forum thread for each problem you want to report in the future. This way the updates on the current case will be much easier to track. That being said, let us continue the discussion in your initial forum thread.

    All the best,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  7. Mohamad
    Mohamad avatar
    15 posts
    Member since:
    Feb 2012

    Posted 04 Mar 2012 Link to this post

    Thanks Fravarn
    -------------------------
    Got a question about ajax
    I have code as follows.

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
         <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
     <asp:GridView ID="GridView1" runat="server"  DataKeyNames="TopicID"
            AutoGenerateColumns="False" ShowHeader="False" BorderStyle="None"
            GridLines="None" Width="100%" onrowcommand="GridView1_RowCommand">
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <telerik:radrating ID="RadRating1" OnRate="RadRating1_Rate" AutoPostBack="True" Runat="server" Skin="Forest" Orientation="Horizontal"  SelectionMode="Single" ItemCount="5" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>

        </ContentTemplate>
        </asp:UpdatePanel>
    _____
    CodeBehin
     protected void RadRating1_Rate(object sender, EventArgs e)
        {

            RadRating rating = (RadRating)sender;
            GridViewRow row = (GridViewRow)rating.NamingContainer;
            string ID = GridView1.DataKeys[row.RowIndex].Value.ToString();
        }
    __________
    then Is Problem in sending
    What do you recommend you send a Ajax
  8. Slav
    Admin
    Slav avatar
    1356 posts

    Posted 06 Mar 2012 Link to this post

    Hi Mohamad,

    Please check this forum thread, in which I have already addressed your problem. Let us continue our discussion there, as it appears that it is related to the same case and we will be able to resolve your issue much faster if it is described in a single thread.

    Greetings,
    Slav
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017