Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-08-16
3
Medium Priority
?
298 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 2000 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

Google Certified Professional - Cloud Architect

This course (1 of 3) is designed to help students who are interested in Google Cloud Platform (GCP) to become familiar with the platform, navigate the console and learn its capabilities. It will also prepare students for the Google Cloud Architect certification exam.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 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