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. Better way of definding label control at run time

Better way of definding label control at run time

Scheduled Pinned Locked Moved ASP.NET
csharphelpasp-netvisual-studio
3 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.
  • I Offline
    I Offline
    imranafsari
    wrote on last edited by
    #1

    Hi all , I am using C# , asp.net ,visual studio 2005. I am defining label control at runtime as Label item1 = new Label(); And assigning its id as Item1.ID = "item1"; But problem is that I have to define it for 250 label control. Actually I tried it to define through loop but its not working. Is better way of coding posiible or we have to define all 250 label control Please help Thanks imran khan

    S B 2 Replies Last reply
    0
    • I imranafsari

      Hi all , I am using C# , asp.net ,visual studio 2005. I am defining label control at runtime as Label item1 = new Label(); And assigning its id as Item1.ID = "item1"; But problem is that I have to define it for 250 label control. Actually I tried it to define through loop but its not working. Is better way of coding posiible or we have to define all 250 label control Please help Thanks imran khan

      S Offline
      S Offline
      Sandeep Akhare
      wrote on last edited by
      #2

      But why you want to define 250 labels ? Can you tell the business requirement behind so that could help you more that just giving answer

      Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

      1 Reply Last reply
      0
      • I imranafsari

        Hi all , I am using C# , asp.net ,visual studio 2005. I am defining label control at runtime as Label item1 = new Label(); And assigning its id as Item1.ID = "item1"; But problem is that I have to define it for 250 label control. Actually I tried it to define through loop but its not working. Is better way of coding posiible or we have to define all 250 label control Please help Thanks imran khan

        B Offline
        B Offline
        Brent Lamborn
        wrote on last edited by
        #3

        This works fine for me:

         for (int i = 0; i < 250; i++)
                {
                    Label l = new Label();
                    l.ID = "label" + i.ToString();
                    l.Text = i.ToString();
                    this.Controls.Add(l);
                }
        

        Can you share some code? What do you mean it is not working? What is it doing?


        "Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.

        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