Solved

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

Posted on 2010-08-16
3
292 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

822 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