Solved

ASP.net Repeater and For Loop TextBox

Posted on 2014-03-14
2
1,110 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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now