FindControl

Repeater中的TextBox1

   <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="Repeater1_ItemCommand">
        <ItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox><%#DataBinder.Eval(Container.DataItem,"ProductName")%><asp:Button ID="btn" OnClick="btn_click" runat="server" Text="dddd" /><br />
        </ItemTemplate>
        </asp:Repeater>

通过按钮来获得TextBox1:

    protected void btn_click(object sender, EventArgs e)
    {
        //获得按钮
        Button btn = (Button)sender;
        TextBox tb = (TextBox)btn.Parent.FindControl("TextBox1");
        tb.Text = "Text";
    }

或者

  foreach (RepeaterItem item in this.Repeater1.Items)
        {
            ((TextBox)item.FindControl("TextBox1")).Text = "Text2";
        }

你可能感兴趣的:(find)