CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    22

    add values to dropdownlist

    i have a code...

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    for (int i = 1; i <= 100; i++)
    {
    ListItem itm = new ListItem("i");

    DropDownList1.Items.Add(itm);


    }
    }

    I need to add values to a dropdownlist from 1 to 100...
    but i get 100 i's displayed..
    Please tell me how..
    THanks

  2. #2
    Join Date
    Feb 2009
    Posts
    112

    Re: add values to dropdownlist

    Quote Originally Posted by jagmit View Post
    i have a code...

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    for (int i = 1; i <= 100; i++)
    {
    ListItem itm = new ListItem("i");

    DropDownList1.Items.Add(itm);


    }
    }

    I need to add values to a dropdownlist from 1 to 100...
    but i get 100 i's displayed..
    Please tell me how..
    THanks
    You have your variable i in quotes thus making it a string so it is listing a string 100 times. try removing the quotes.

    This would also work
    Code:
                 
                for (int i = 1; i <= 100; i++)
                {
                    DropDownList1.Items.Add(i);
                }
    Last edited by vandel212; September 30th, 2009 at 12:07 PM.
    - It's a long way to the top if you want to rock n' roll - AC/DC

    Check out my band and support the music:
    www.blueruinmusic.com

  3. #3
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: add values to dropdownlist

    Try

    Code:
    for (int i = 1; i <= 100; i++)
    {
        DropDownList1.Items.Add(i.ToString());
    }
    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  4. #4
    Join Date
    Jan 2009
    Posts
    22

    Re: add values to dropdownlist

    Darwen thanks, it worked just fine..
    vandel212 that worked too....

    Thanks guys..

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured