2009-05-20 104 views
0

我想訪問與其中啓動ItemCommand的RepeaterItem關聯的數據。該方案是,我有一個Button控件在命令設置聲明這樣多RepeaterItems:在命令執行中訪問與RepeaterItem相關聯的數據

<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> 

後面的代碼是:

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 

回答

3

您可以使用e.Item.DataItem強制轉換來獲得直到對象的數據,或者您可以將其存儲在隱藏字段中。

1

建立在Mitchel說的基礎上,確保檢查RowType是否爲DataRow。當你不能做時不想做廢話。從e.Item.DataItem到您的類型的轉換在頁眉或頁腳行上失敗。