Pre select multiple listbox items(newbie)

Discussion in 'ASP .Net' started by Angela, Jun 3, 2004.

  1. Angela

    Angela Guest

    Hi

    I am having trouble doing this simple task:

    What I want to do is pre select the listbox called ltbLanguage (which
    allows multiple selections).

    while dtr.read()
    for i = 0 to dtr.fieldcount-1
    ltbLanguage.selectedIndex = dtr("language_id")
    next
    end while

    At the moment it is only selecting one item even though there is more
    than one record returned from the DB

    Thanks

    Angela
     
    Angela, Jun 3, 2004
    #1
    1. Advertising

  2. Hi

    myListBox.Items[ iIndex ].Selected = true;

    --
    Best Regards
    Vidar Petursson
    ==============================
    Microsoft Visual: Scripting MVP 2000-2004
    http://www.icysoft.com/
    http://www.deus-x.com/ Instant e-commerce
    http://www.microsoft.com/technet/scriptcenter/
    Playground: http://213.190.104.211/ ( IE 5.5+ only )

    No matter where you go there you are
    ==============================
    "Angela" <> wrote in message
    news:...
    > Hi
    >
    > I am having trouble doing this simple task:
    >
    > What I want to do is pre select the listbox called ltbLanguage (which
    > allows multiple selections).
    >
    > while dtr.read()
    > for i = 0 to dtr.fieldcount-1
    > ltbLanguage.selectedIndex = dtr("language_id")
    > next
    > end while
    >
    > At the moment it is only selecting one item even though there is more
    > than one record returned from the DB
    >
    > Thanks
    >
    > Angela
     
    Vidar Petursson, Jun 3, 2004
    #2
    1. Advertising

  3. Hi Angela

    Sample code in ASP.NET with C# for ur req
    (ltbLanguage -> ListBox control (Web Control)

    ListItem lstItem = null

    while (dtr.read()

    for (i = 0;i< dtr.fieldcount-1;i++

    lstItem = ltbLanguage.Items.FindByValue(dtr("language_id").ToString());
    if (lstItem != null

    lstItem.Selected = true




    You can also use the FindByName() function if ur search is based on Text value of the ListBox

    Hope this cud help u out. Let me know, if ur req. is not in C# language

    Regards
    Kamalanathan T
     
    =?Utf-8?B?S2FtYWx0?=, Jun 3, 2004
    #3
  4. Angela

    Angela Lam Guest

    I am using VB

    Angela



    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Angela Lam, Jun 3, 2004
    #4
  5. Angela

    Angela Lam Guest

    Thanks for your help guys, figured it out!!



    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Angela Lam, Jun 3, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kent
    Replies:
    1
    Views:
    910
    Andrew de la Harpe
    May 3, 2004
  2. K B
    Replies:
    2
    Views:
    701
  3. divya
    Replies:
    1
    Views:
    1,121
    Munna
    May 28, 2008
  4. Tomas
    Replies:
    1
    Views:
    600
    Munna
    Aug 12, 2008
  5. mc
    Replies:
    0
    Views:
    260
Loading...

Share This Page