Solved

How to find/iterate over controls in a CustomControl embedded in an ASP:Repeater control?

Posted on 2010-08-16
3
295 Views
Last Modified: 2013-11-11
Hi:

I have an ASP .Net page that contains a repeater control.
The item template for the repeater control contains a custom (ascx) user control.
That control contains a text/input box.
I've added a custom attribute to the definition of that text box.


On the server, I'd like to iterate over all the text box so I can sum their values.
Since I've got to convert the textbox's values to type decimal, I'd be happy with
just finding a clean way to iterate over the controls.

It feels like there should be some (relatively) straight forward LINQ based solution.


This is what my page looks like:
---------------------------------------

 <asp:Repeater>
    <ItemTemplate>
        <uc1:SomeUserControl ID="UserControl" runat="server"
                        FullName='<%# DataBinder.Eval(Container.DataItem, "FullName") %>'
                        Amount='<%# DataBinder.Eval(Container.DataItem, "Amount") %>'  
        />

    </ItemTemplate>
 </asp:Repeater>


This is what my user (ASCX) control looks like:
(Notice I have the Custom Attribute "Payment" set)
---------------------------------------------------------
<div class="row">
    <asp:Label ID="lFullName" runat="server" />
    <asp:TextBox ID="tAmount" Width="100" runat="server" Payment="true" />
</div>    


Thanks,
JohnB
0
Comment
Question by:jxbma
[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
3 Comments
 
LVL 5

Accepted Solution

by:
vivekpv10 earned 500 total points
ID: 33451556
0
 
LVL 8

Expert Comment

by:Fareed Ali Khan
ID: 33451660
Hi,

Use the ItemDataBound event of the Repeater for updating the values of TextBox like the following:

Don't forget to attach the ItemDataBound event with the repeater:

 <asp:Repeater OnItemDataBound="ItemDataBound">
    <ItemTemplate>
        <uc1:SomeUserControl ID="UserControl" runat="server"
                        FullName='<%# DataBinder.Eval(Container.DataItem, "FullName") %>'
                        Amount='<%# DataBinder.Eval(Container.DataItem, "Amount") %>'  
        />

    </ItemTemplate>
 </asp:Repeater>


protected void ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
      SomeUserControl lContainer = (SomeUserControl)e.Item.FindControl("UserControl");
      lContainer.tAmount.Text = "Sum the numbers here";
}
}

Open in new window

0
 
LVL 1

Author Closing Comment

by:jxbma
ID: 33455350
Yes, that's what I was afraid.., doing a nested loop. I thought there might be a more elegant way doing it with LINQ.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API v SOA 8 64
Textbox autocomplete using jquery in asp.net 13 50
How does this modal work? 3 34
Click print button programmatically on print showdialog 1 24
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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