TemplateItem - DetailView - Appeler un control
Bonjour,
Y-a-t-il une façon plus simple que la suivante pour appeler un contrôle TemplateItem que j'ai mis dans un DetailsView ? Voici ce que j'ai trouvé en ligne et dont je n'ai pas modifié :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| private Control FindControlRecursive(Control ctlRoot, string sControlId)
{
// if this control is the one we are looking for, break from the recursion
// and return the control.
if (ctlRoot.ID == sControlId)
{
return ctlRoot;
}
// loop the child controls of this parent control and call recursively.
foreach (Control ctl in ctlRoot.Controls)
{
Control ctlFound = FindControlRecursive(ctl, sControlId);
// if we found the control, return it.
if (ctlFound != null)
{
return ctlFound;
}
}
// we never found the control so just return null.
return null;
} |
ET ensuite dans le Page_Load :
Code:
1 2 3 4
| DropDownList conciliation = (DropDownList)FindControlRecursive(DetailsView1, "DropDownList3");
Calendar DateCompt = (Calendar)FindControlRecursive(DetailsView1, "Calendar1");
Label DateModif = (Label)FindControlRecursive(DetailsView1, "Label2");
Label DateSaisi = (Label)FindControlRecursive(DetailsView1, "Label3"); |
Vous pouvez voir que ça devient lourd assez rapidement.... Est-il possible d'être plus efficace?
Merci de l'information et de votre temps!