2

如何获得位于另一个中继器中的文本框?

<asp:Repeater ID="Repeater1" runat="server">
 <ItemTemplate>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
      <asp:Repeater ID="Repeater2" runat="server">
         ....
       </asp:Repeater>
  </ItemTemplate>
</asp:Repeater>

我在 repeater2 ItemDataBound 中,我需要获取 TextBox1 的值,我该怎么做。

 Protected Sub Repeater2_ItemDataBound(sender As Object, e As System.Web.UI.WebControls.RepeaterItemEventArgs)  

??

    End Sub
4

2 回答 2

4

NamingContainer内部中继器的 是外部RepeaterItemRepeater,然后用于FindControl获取对 的引用TextBox

protected void Repeater2_ItemDataBound(Object sender, RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
        Repeater innerRepeater = (Repeater) sender;
        RepeaterItem outerItem = (RepeaterItem) innerRepeater.NamingContainer;
        TextBox TextBox1 = (TextBox) outerItem.FindControl("TextBox1");
    }
}
于 2013-04-22T14:39:46.987 回答
1

你应该能够做到:

Dim tb = DirectCast(sender, WebControl).NamingContainer.FindControl("TextBox1")
于 2013-04-22T14:41:14.847 回答