?
Solved

ASP.net Repeater and For Loop TextBox

Posted on 2014-03-14
2
Medium Priority
?
1,365 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 Ageil
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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

840 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