Accessing a specific control(s) on the Repeater Control

Akiii
Posted by Akiii under ASP.NET category on | Points: 40 | Views : 1205
Suppose, I have Repeater :-

<asp:repeater ID="Repeater1" runat="server" >
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Button on row 1" />
<asp:TextBox ID="TextBox1" runat="server" Text="Text on row 2" />
<br />
</ItemTemplate>
</asp:repeater>


Page behind code :-

if (!Page.IsPostBack)
{
ArrayList arr = new ArrayList();
arr.Add(1);
arr.Add(2);
arr.Add(3);
arr.Add(4);
arr.Add(5);
arr.Add(6);

Repeater1.DataSource = arr;
Repeater1.DataBind();
}


You can iterate through the Repeater1 and access the TextBoxes one by one.

foreach (RepeaterItem rptItem in Repeater1.Items)
{
TextBox textbox = (TextBox)rptItem.FindControl("TextBox1");
//Do something with the TextBox
}



Thanks and Regards
Akiii

Comments or Responses

Login to post response