?
Solved

find repeaters to bind to

Posted on 2007-08-10
3
Medium Priority
?
266 Views
Last Modified: 2010-04-15
Originally in this code they had 3 seperate methods looking up and binding data to 2 repeaters and one datalist on the page.

The controls on the page are named:

Type1 (repeater)
Type2 (repeater)
Type3 (datalist)

Each method does this:

Type1.DataSource = DS;
Type1.DataBind();

Type2.DataSource = DS;
Type2.DataBind();

Type3.DataSource = DS;
Type3.DataBind();

So instead of 3 methods i placed one method in a loop that loops 3 times...

for (int i = 1; i <= 3; i++)
{
   ...
}

At the end of the loop how would i find and target each control to bind to?

Nugs
0
Comment
Question by:Nugs
3 Comments
 
LVL 14

Expert Comment

by:existenz2
ID: 19677512
If I understand your problem correctly, you want to simplify the following code?:
Type1.DataSource = DS;
Type1.DataBind();

Type2.DataSource = DS;
Type2.DataBind();

Type3.DataSource = DS;
Type3.DataBind();

I wouldn't try to simplify this. It is a very clean and good way to databind. You shouldn't make it to complex if it is not nessary. In this case (from what I understand from your question) the repeaters and datalist are not added dynamicly and it is always known what to bind to which item.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 19679236
for (int i = 1; i <= 3; i++)
{
   Repeater rpt = (Repeater)this.FindControl("Type" + i);
   rpt.DataSource = DS;
   rpt.DataBind();
}

Bob
0
 
LVL 2

Author Comment

by:Nugs
ID: 19687735
Thanks bob..

Nugs
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

850 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