How to use an array of HtmlGenericControl
-
How do i use an array of HtmlGenericControl. This is how i have tried to use. HtmlGenericControl objUl = new HtmlGenericControl("ul"); HtmlGenericControl objLi = new HtmlGenericControl[5]("li"); objUl.ID = "nav"; objLi[0].InnerHtml = "First element"; objLi[1].InnerHtml = "Second Element"; objUl.Controls.Add(objLi[0]); objUl.Controls.Add(objLi[1]); mainDiv.Controls.Add(objUl); where mainDiv is a server
control. It is giving following error Cannot apply indexing with [] to an expression of type 'System.Web.UI.HtmlControls.HtmlGenericControl' Is it correct approach to build html body with an array of HtmlGenericControl? if yes then how do i use it . If no then whjat should be the approach....?please help
-
How do i use an array of HtmlGenericControl. This is how i have tried to use. HtmlGenericControl objUl = new HtmlGenericControl("ul"); HtmlGenericControl objLi = new HtmlGenericControl[5]("li"); objUl.ID = "nav"; objLi[0].InnerHtml = "First element"; objLi[1].InnerHtml = "Second Element"; objUl.Controls.Add(objLi[0]); objUl.Controls.Add(objLi[1]); mainDiv.Controls.Add(objUl); where mainDiv is a server
control. It is giving following error Cannot apply indexing with [] to an expression of type 'System.Web.UI.HtmlControls.HtmlGenericControl' Is it correct approach to build html body with an array of HtmlGenericControl? if yes then how do i use it . If no then whjat should be the approach....?please help
HtmlGenericControl[] objLi = {new HtmlGenericControl(),new HtmlGenericControl(),new HtmlGenericControl(), new HtmlGenericControl(), new HtmlGenericControl()}:
objLi[0].InnerHtml = "First element";
objLi[1].InnerHtml = "Second Element";All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
modified on Wednesday, December 19, 2007 7:32:47 AM
-
HtmlGenericControl[] objLi = {new HtmlGenericControl(),new HtmlGenericControl(),new HtmlGenericControl(), new HtmlGenericControl(), new HtmlGenericControl()}:
objLi[0].InnerHtml = "First element";
objLi[1].InnerHtml = "Second Element";All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
modified on Wednesday, December 19, 2007 7:32:47 AM
except that will fail with Null reference exception as you have not instantiated objLi[0] or objLi[1]
HtmlGenericControl[] objLi = new HtmlGenericControl[5]; objLi[0] = new HtmlGenericControl(); objLi[0].InnerHtml = "First element"; objLi[1] = new HtmlGenericControl(); objLi[1].InnerHtml = "Second Element";
-
except that will fail with Null reference exception as you have not instantiated objLi[0] or objLi[1]
HtmlGenericControl[] objLi = new HtmlGenericControl[5]; objLi[0] = new HtmlGenericControl(); objLi[0].InnerHtml = "First element"; objLi[1] = new HtmlGenericControl(); objLi[1].InnerHtml = "Second Element";
exactly. I was on a mobile. So became lazy to type ! :)
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions