Solved

ASP.net Repeater and For Loop TextBox

Posted on 2014-03-14
2
1,171 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
[X]
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
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Looking for a link to download the latest .NET redistribution package 5 33
how to check mis-spellings in a select SQL 2 38
Json and ajax 1 22
orderby list (from Json) 1 30
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…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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