• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1431
  • Last Modified:

ASP.net Repeater and For Loop TextBox

I have a repeater that will loop the textboxes and label.
My questions. I can I get the label and textbox value inside of the FOR LOOP.
It is not just one label / textbox. It will have at least 10 to 15 rows depended on the database table.


<asp:Repeater runat="server" ID="commonInformationList">
                                     <div class="form-group">                                                
                                                 <label class="col-sm-4 control-label"><b><%# Eval("DescriptionAndInputHint") %>:</b></label>                                                
                                                 <div class="col-sm-8"><asp:TextBox runat="server" ID="commonInformationValue" CssClass="form-control"></asp:TextBox>
1 Solution
Your question is unclear.
Are you trying to use a loop on the client side or the server side?

You don't need a loop if you want to capture the values on the server side, you can do that on the repeater's ItemDataBound event
The event is documented here

On the client side, it is also possible but it would require some extra work.
Manoj PatilSr. Software EngineerCommented:
It is easy to find
Check this Helper Method

public static Control FindControlRecursive(Control root, string id)
   if (root.ID == id) 
     return root;

   return root.Controls.Cast<Control>()
      .Select(c => FindControlRecursive(c, id))
      .FirstOrDefault(c => c != null);

Open in new window

And use this by following way
1. for TextBox

foreach (RepeaterItem repeated in rptBudget.Items)
   TextBox commonInformationValue=            
      (TextBox)FindControlRecursive(repeated, "commonInformationValue");       

Open in new window

2. for Label
foreach (RepeaterItem repeated in rptBudget.Items)
   Label lblControl =            
      (Label)FindControlRecursive(repeated, "lblControl");       

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now