Geeks With Blogs

AzamSharp Some day I will know everything. I hope that day never comes.
Sometimes we need to set the style sheet of a particular control dynamically. This can easily be done by traversing down the Page Control Hirarchy.

private void Button1_Click(object sender, System.EventArgs e)
			// I made 10 Labels controls dynamically and put them inside the Panel control
			int counter = 0; 

			string style = ddlStyle.SelectedItem.Value; 
			// Go into the Page Control Collection
			foreach(Control c in Page.Controls) 
					// Go inside the form element 
					foreach(Control c2 in c.Controls) 
						// go inside the Panel control 
						foreach(Control c3 in c2.Controls) 
							// Check if the control is label or not 
							if(c3.GetType() == new Label().GetType()) 
								// Set the CSS class 
								Label l = (Label) c3;
								// Set the Style 
								l.CssClass = style; 



Posted on Saturday, September 10, 2005 3:11 PM | Back to top

Comments on this post: Set Style Sheet of a Control Dynamically

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Mohammad Azam | Powered by: