我有Repeater
这样的结构:
<asp:Repeater ID="rptListClaimTypes" runat="server">
<ItemTemplate>
<asp:FileUpload ID="fuContract" runat="server" />
<asp:LinkButton ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" CommandName='<%# Eval("ClaimTypeID")%>' />
</ItemTemplate>
</asp:Repeater>
我需要在点击btnUpload
时处理文件上传。我可以使用sender
访问触发子例程的控件。我如何访问fuContract
?
Protected Sub btnUpload_Click(sender As Object, e As EventArgs)
Dim ClaimTypeID As Integer = sender.CommandName
Dim fuContract As FileUpload = '??
End Sub
答案 0 :(得分:1)
使用当前的事件处理方法,您可以将发送方转换为LinkButton,将父级转换为RepeaterItem,然后使用FindControl查找FileUpload控件:
Dim fuContract As FileUpload = CType(CType(sender, LinkButton).Parent.FindControl("fuContract"), FileUpload)
我更喜欢使用Repeater的ItemCommand Event来处理这些类型的事件:
Private Sub rptListClaimTypes_ItemCommand(source As Object, e As RepeaterCommandEventArgs) Handles rptListClaimTypes.ItemCommand
Dim fuContract As FileUpload = CType(e.Item.FindControl("fuContract"), FileUpload)
End Sub