This is a migrated thread and some comments may be shown as answers.

auto postbak rate value to template grid

6 Answers 84 Views
Rating
This is a migrated thread and some comments may be shown as answers.
Mohamad
Top achievements
Rank 1
Mohamad asked on 25 Feb 2012, 08:36 AM
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

6 Answers, 1 is accepted

Sort by
0
Mohamad
Top achievements
Rank 1
answered on 26 Feb 2012, 11:39 AM
help me
0
Mohamad
Top achievements
Rank 1
answered on 26 Feb 2012, 01:01 PM
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);
        }
    }

0
Mohamad
Top achievements
Rank 1
answered on 28 Feb 2012, 10:31 AM
 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);
            }     
        }
    }
0
Slav
Telerik team
answered on 29 Feb 2012, 01:00 PM
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.
0
Mohamad
Top achievements
Rank 1
answered on 04 Mar 2012, 07:57 AM
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
0
Slav
Telerik team
answered on 06 Mar 2012, 05:52 PM
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.
Tags
Rating
Asked by
Mohamad
Top achievements
Rank 1
Answers by
Mohamad
Top achievements
Rank 1
Slav
Telerik team
Share this question
or