How to use an array of HtmlGenericControl - TechRepublic
Question
December 19, 2007 at 03:57 AM
packer.lean

How to use an array of HtmlGenericControl

by packer.lean . Updated 18 years, 7 months ago

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

This discussion is locked

All Comments