Solved

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

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
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…

636 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