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

How to identify a row when a button is clicked

1 Answer 291 Views
ListView
This is a migrated thread and some comments may be shown as answers.
DuelingCats
Top achievements
Rank 2
DuelingCats asked on 01 Aug 2012, 09:06 PM
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. 

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

1 Answer, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 03 Aug 2012, 11:17 AM
Hello Justin,

You could try the following approach:
  mark-up:
<telerik:RadButton ... OnClick="TaskStateChange_Clicked">
  code-behind:
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.

Greetings,
Eyup
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
ListView
Asked by
DuelingCats
Top achievements
Rank 2
Answers by
Eyup
Telerik team
Share this question
or