Trap DataGrid in a each control loop

M

marc-andr?

Hi,

I have to loop on each control on a webforms...

I use this function :

public void LoopOnAllControls(ControlCollection coll)
{
foreach (System.Web.UI.Control ctrl in coll)
{
if(ctrl.HasControls())
{
LoopOnAllControls(ctrl.Controls);
}
else
{
SetTheStyleClass(ctrl);
}

}

}


public void SetTheStyleClass(Control ct)
{
string TypeCt;
TypeCt = ct.GetType().ToString();

switch (TypeCt)
{

case "System.Web.UI.HtmlControls.HtmlAnchor" :
{
(ct as HyperLink).CssClass = HyperLink;
break;
}

case "System.Web.UI.HtmlControls.HtmlButton" :
{
(ct as Button).CssClass = BoutonDeCommande;
break;
}

case "System.Web.UI.WebControls.Button" :
{
(ct as Button).CssClass = BoutonDeCommande;
break;
}

case "System.Web.UI.HtmlControls.HtmlInputText" :
{
(ct as TextBox).CssClass = BoiteDeTextte ;
break;
}

case "System.Web.UI.WebControls.TextBox" :
{
(ct as TextBox).CssClass = BoiteDeTextte ;
break;
}

case "System.Web.UI.WebControls.Label" :
{
(ct as Label).CssClass = TexteOrdinaire ;
break;
}

case "System.Web.UI.WebControls.ListBox" :
{
(ct as ListBox).CssClass = ListAndComboBox;
break;
}

case "System.Web.UI.WebControls.DropDownList" :
{
(ct as DropDownList).CssClass = ListAndComboBox;
break;
}

case "System.Web.UI.WebControls.HyperLink" :
{
(ct as HyperLink).CssClass = HyperLink;
break;
}




case
"System.Web.UI.WebControls.DataGrid" :
{
//They never enter here!!!!!
DataGrid dtg = ct as DataGrid;

for(int i=0;i<dtg.Items.Count;i++)
{
dtg.Items.CssClass= "texte";
}

break;
}

}
}

}


the " SetTheStyleClass" is use for setting my CssClass on the
control... anyway there's my problem

It's works well for any control... but not with the DataGrid. I don't
know why?? I can't trap the DataGrid control...

Anyone have an idea!?
 
G

Guest

Has the Datagrid been bound before doing this loop. Also you may want to
revise your code. Iterating through each control can be detrimental to
performance.
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top