Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ASP.net Repeater and For Loop TextBox

Posted on 2014-03-14
2
1,154 Views
Last Modified: 2014-03-31
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.

Thanks

<asp:Repeater runat="server" ID="commonInformationList">
                                    <ItemTemplate>
                                     <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>
                                                 </div>                                                
                                            </div>    
                                    </ItemTemplate>
                                  </asp:Repeater>
0
Comment
Question by:CoolDev2014
2 Comments
 
LVL 27

Expert Comment

by:Sammy
ID: 39930148
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
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemdatabound(v=vs.110).aspx

On the client side, it is also possible but it would require some extra work.
0
 
LVL 19

Accepted Solution

by:
Manoj Patil earned 500 total points
ID: 39932470
Yes,
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

0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question