How to identify a row when a button is clicked

2 posts, 1 answers
  1. DuelingCats
    DuelingCats avatar
    54 posts
    Member since:
    Jul 2012

    Posted 01 Aug 2012 Link to this post

    I have a listview and each row has a RadButton in a column. I need to identify which row's button was clicked on the click event. The row describes a specific row in my database and I need to set a disable/enable column based upon the button clicked. Here is my item template for my ListView. I just need to figure out which row the button belongs on to get the ID. Thanks. 

        <tr class="rlvI">
                <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' />
                <asp:Label ID="TASK_NAMELabel" runat="server" Text='<%# Eval("TASK_NAME") %>' />
                <asp:Label ID="NEXT_RUNLabel" runat="server" Text='<%# Eval("NEXT_RUN") %>' />
                <asp:Label ID="FREQUENCYLabel" runat="server"  Text='<%# Eval("FREQUENCY") %>' />
                <telerik:RadButton ID="ENABLEDToggle" runat="server" Width=75 ButtonType="StandardButton" 
                ToggleType="CustomToggle" Checked='<%# Enabled_Converter(Eval("ENABLED")) %>' OnCheckedChanged="TaskStateChange_Clicked">
                        <telerik:RadButtonToggleState Text="Enabled" />
                        <telerik:RadButtonToggleState Text="Disabled" />
  2. Answer
    Eyup avatar
    3786 posts

    Posted 03 Aug 2012 Link to this post

    Hello Justin,

    You could try the following approach:
    <telerik:RadButton ... OnClick="TaskStateChange_Clicked">
    protected void TaskStateChange_Clicked(object sender, EventArgs e)
        RadButton button = sender as RadButton;
        RadListViewDataItem item = button.Parent as RadListViewDataItem;
        int displayIndex = item.DisplayIndex;
        int dataItemIndex = item.DataItemIndex;

    You could also extract the values from the current item as demonstrated in the following demo:
     ListView / Selecting items

    I hope this will prove helpful.

    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