Solved

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

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
crm development 2 37
ASP.NET e-commerce website 4 30
Vb.net/SQL prevent a table from being deleted ever 7 21
Birthdays 3 14
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

23 Experts available now in Live!

Get 1:1 Help Now