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

Determine which link was clicked inside RadRotator

2 Answers 82 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Ronnie
Top achievements
Rank 1
Ronnie asked on 09 Feb 2012, 10:26 PM
I have a RadRotator with 2 different LinkButtons inside the template.  Each LinkButton has a command argument that is pulled from the database.  What is the easiest way to determine which LinkButton was clicked in the Rotator_ItemClick event?  The problem that I am having is that I can't determine which LinkButton was clicked so that I can execute specific server side code.  

<telerik:RadRotator ID="RadRotator1" runat="server"
    DataSourceID="dsProducts" RotatorType="CoverFlowButtons" Skin="Forest" Width="625px"
    Height="350px" ItemHeight="350px" ItemWidth="551px" PauseOnMouseOver="true"
        BorderStyle="None">
    <ItemTemplate>
        <asp:LinkButton ID="lnkAddTestimonial" runat="server" CommandName="AddTestimonial"
        CommandArgument='<%# Eval("ProductID") %>'>Add Review</asp:LinkButton>
        <asp:LinkButton ID="lnkViewTestimonials" runat="server" CommandName="ViewTestimonials"
        CommandArgument='<%# Eval("ProductID") %>'>Read Reviews</asp:LinkButton>
    </ItemTemplate>
</telerik:RadRotator>

2 Answers, 1 is accepted

Sort by
0
Accepted
Kevin
Top achievements
Rank 2
answered on 13 Feb 2012, 03:00 PM
Hello Ronnie,

You should create a separate event handler for the two LinkButtons. So you create a single event handler called Testimonial_Command and attach it to both of the buttons. Like so:

ASPX:
<telerik:RadRotator ID="RadRotator1" runat="server"
    DataSourceID="dsProducts" RotatorType="CoverFlowButtons" Skin="Forest" Width="625px"
    Height="350px" ItemHeight="350px" ItemWidth="551px" PauseOnMouseOver="true"
        BorderStyle="None">
    <ItemTemplate>
        <asp:LinkButton ID="lnkAddTestimonial" runat="server" CommandName="AddTestimonial"
        CommandArgument='<%# Eval("ProductID") %>' OnCommand="Testimonial_Command">Add Review</asp:LinkButton>
        <asp:LinkButton ID="lnkViewTestimonials" runat="server" CommandName="ViewTestimonials"
        CommandArgument='<%# Eval("ProductID") %>' OnCommand="Testimonial_Command">Read Reviews</asp:LinkButton>
    </ItemTemplate>
</telerik:RadRotator>

Code:

protected void Testimonial_Command(object sender, CommandEventArgs e)
{
    if (e.CommandName == "AddTestimonial")
    {
        // do this
    }
    else if (e.CommandName == "ViewTestimonial")
    {
        // do this instead
    }
}

I hope that helps.
0
Ronnie
Top achievements
Rank 1
answered on 13 Feb 2012, 03:35 PM
That is perfect, exactly what I was looking to do.  Thanks so much.
Tags
Rotator
Asked by
Ronnie
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Ronnie
Top achievements
Rank 1
Share this question
or