TRY THIS

J

Junaid Arif

private Control GetElementInRepeater(string controlID)
{
foreach (Control c in Repeater1.Controls)
{
if (!(FindControl(c.UniqueID).FindControl(controlID)!=null))
{
return (FindControl(c.UniqueID).FindControl(controlID));
}
}
return null;
}

This would do you will get a Control Array of all elements within the Repeater or any other such control..

Regards
Junaid Arif


EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com/default.aspx?ref=ng
 
G

Göran Andersson

Junaid said:
private Control GetElementInRepeater(string controlID)
{
foreach (Control c in Repeater1.Controls)
{
if (!(FindControl(c.UniqueID).FindControl(controlID)!=null))

Why do you use FindContol to get a reference to the control that you
already have a reference to?

You got mixed up in the double negations in the expression. The
condition will be true if FindControl returns null. That means that the
method always returns null.
{
return (FindControl(c.UniqueID).FindControl(controlID));
}
}
return null;
}

Get the reference in a variable, so that you don't have to call
FindControl again to get the reference:

private Control GetElementInRepeater(string controlID) {
foreach (Control c in Repeater1.Controls) {
Control child = c.FindControl(controlID);
if (child != null) {
return child;
}
}
return null;
}
This would do you will get a Control Array of all elements within the Repeater or any other such control..

Regards
Junaid Arif


EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com/default.aspx?ref=ng

Is it the EggHeadCafe that is broken, or did you mistakenly post a new
thread instead of replying to one?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top