Accessing data associated with executing the RepeaterItem on Command

I want to access the data associated with the RepeaterItem in which the ItemCommand fires. The scenario is that I have several RepeaterItems that control a Button 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>

      

Code behind:

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

      

0


a source to share


2 answers


You can use e.Item.DataItem to navigate to data for an object or store it in a hidden field.



+3


a source


Based on what Mitchell said, make sure you check that the RowType of the DataRow . You don't want to do shit when you can't. Casting from e.Item.DataItem to your type will result in an error in the header or footer bar.



+1


a source







All Articles