views:

418

answers:

2

Hi guys, I want to access the data associated with the RepeaterItem in which an ItemCommand fired up. The scenario is, I have multiple RepeaterItems which Button controls in which the Command is set declaratively like this:

<asp:Repeater ID="Repeater3" runat="server" DataSource='<%# ClientManager.GetClientEmployees(Eval("ClientID")) %>' OnItemCommand="RemoveEmployeeFromClient">
                                                                <ItemTemplate>
                                                                    <asp:LinkButton ID="LinkButton1" runat="server" Text="(x)" CommandName="RemoveEmployeeFromClient"></asp:LinkButton>
                                                                </ItemTemplate>
                                                                <SeparatorTemplate>,<br /></SeparatorTemplate>
                                                            </asp:Repeater>

Thye code behind is:

Protected Sub RemoveEmployeeFromClient(ByVal source As Object, ByVal e As RepeaterCommandEventArgs)
        ' I want to access the data associated with the RepeaterItem which the Button was clicked.
    End Sub

Any tips guys? Thanks in advance!

+3  A: 

You can use e.Item.DataItem to get down to the data for the object, or you could store it in a hidden field.

Mitchel Sellers
+1  A: 

Building on what Mitchel said, make sure you check to see that the RowType is DataRow. Don't want to do crap when you can't. The cast from e.Item.DataItem to your type would fail on the header or footer row.

Gromer