Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to use an array of HtmlGenericControl

How to use an array of HtmlGenericControl

Scheduled Pinned Locked Moved ASP.NET
helpquestionhtmldesignsysadmin
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AumSingh
    wrote on last edited by
    #1

    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

    N 1 Reply Last reply
    0
    • A AumSingh

      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

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • N N a v a n e e t h

        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

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        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";

        N 1 Reply Last reply
        0
        • J J4amieC

          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";

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups