Asp:ListBox and selectedindex

Discussion in 'ASP .Net' started by John Giblin, Nov 26, 2003.

  1. John Giblin

    John Giblin Guest

    I have a ListBox within a repeater tag and I am trying to set the selected
    value. I tried the following without success. I was also tryng to make a
    method for the selectedindex but I do not know how to pass the instance of
    this asp:listbox control.

    <asp:ListBox id="ListBox1" name="ListBox1" DataSource='<%#
    GetDropDownQuantities( (BasketLine)DataBinder.Eval(Container,"DataItem"))
    %>'
    Rows="1"
    CssClass="orderselect"
    SelectionMode=Single
    runat="server">
    </asp:ListBox>


    public ListItemCollection GetDropDownQuantities( BasketLine bl)
    {
    ListItemCollection listBoxData = new ListItemCollection();

    int x=0;
    bool isSelected = false;
    while (x++ < 20)
    {
    ListItem li = new ListItem();
    li.Value = x.ToString();
    li.Text = x.ToString();
    if (x==bl.Quantity && !isSelected)
    {
    li.Selected = true;
    isSelected = true;
    }
    listBoxData.Add(li);

    }
    return listBoxData;
    }

    thanks

    John
    John Giblin, Nov 26, 2003
    #1
    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. S. Justin Gengo

    ListBox SelectedIndex is always -1

    S. Justin Gengo, Feb 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,763
  2. =?Utf-8?B?TGll?=
    Replies:
    5
    Views:
    675
    =?Utf-8?B?TGll?=
    Dec 14, 2004
  3. =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=

    ListBox not returning correct SelectedIndex

    =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=, Feb 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    4,275
    Karl Seguin
    Feb 4, 2005
  4. ThunderMusic
    Replies:
    6
    Views:
    1,800
    ThunderMusic
    Dec 12, 2005
  5. devNorway
    Replies:
    3
    Views:
    7,101
    devNorway
    Apr 20, 2006
Loading...

Share This Page