get first and last datavalue field entry of dropdown box

Discussion in 'ASP .Net' started by Paul, Jun 9, 2008.

  1. Paul

    Paul Guest

    probably an easy way to do this but in the code behind I could not see how to
    get the first and last data value field of a dropdown listbox. I have the
    data value field being populated with a table ID and the data text field
    being populated by a table field name. I also have an objectdatasource that
    is bound to the dropdown box so there is probably a way to get the
    information from the objdatasource as well.
    Thanks Paul.
    --
    Paul G
    Software engineer.
    Paul, Jun 9, 2008
    #1
    1. Advertising

  2. On Jun 9, 8:27 pm, Paul <> wrote:
    > probably an easy way to do this but in the code behind I could not see how to
    > get the first and last data value field of a dropdown listbox.  I have the
    > data value field being populated with a table ID and the data text field
    > being populated by a table field name.  I also have an objectdatasource that
    > is bound to the dropdown box so there is probably a way to get the
    > information from the objdatasource as well.
    > Thanks Paul.
    > --
    > Paul G
    > Software engineer.


    Hi Paul

    I think, you can use Items collection

    DropDownList1.Items[0].Value
    DropDownList1.Items[DropDownList1.Items.Count].Value

    Hope this helps
    Alexey Smirnov, Jun 9, 2008
    #2
    1. Advertising

  3. Paul

    Paul Guest

    I think that is what I was looking for, thanks.
    --
    Paul G
    Software engineer.


    "Alexey Smirnov" wrote:

    > On Jun 9, 8:27 pm, Paul <> wrote:
    > > probably an easy way to do this but in the code behind I could not see how to
    > > get the first and last data value field of a dropdown listbox. I have the
    > > data value field being populated with a table ID and the data text field
    > > being populated by a table field name. I also have an objectdatasource that
    > > is bound to the dropdown box so there is probably a way to get the
    > > information from the objdatasource as well.
    > > Thanks Paul.
    > > --
    > > Paul G
    > > Software engineer.

    >
    > Hi Paul
    >
    > I think, you can use Items collection
    >
    > DropDownList1.Items[0].Value
    > DropDownList1.Items[DropDownList1.Items.Count].Value
    >
    > Hope this helps
    >
    >
    Paul, Jun 9, 2008
    #3
  4. On Jun 9, 10:16 pm, Paul <> wrote:
    > I think that is what I was looking for, thanks.
    > --
    > Paul G
    > Software engineer.
    >
    >
    >
    > "Alexey Smirnov" wrote:
    > > On Jun 9, 8:27 pm, Paul <> wrote:
    > > > probably an easy way to do this but in the code behind I could not see how to
    > > > get the first and last data value field of a dropdown listbox.  I have the
    > > > data value field being populated with a table ID and the data text field
    > > > being populated by a table field name.  I also have an objectdatasource that
    > > > is bound to the dropdown box so there is probably a way to get the
    > > > information from the objdatasource as well.
    > > > Thanks Paul.
    > > > --
    > > > Paul G
    > > > Software engineer.

    >
    > > Hi Paul

    >
    > > I think, you can use Items collection

    >
    > > DropDownList1.Items[0].Value
    > > DropDownList1.Items[DropDownList1.Items.Count].Value

    >
    > > Hope this helps- Hide quoted text -

    >
    > - Show quoted text -


    Sorry, I think I did a mistake, collection index is a zero-based and
    you need to use

    DropDownList1.Items[DropDownList1.Items.Count-1].Value

    to get the last item in the list.

    Note, you would need to check the size of the Items collection....

    If DropDownList1.Items.Count>0 Then
    .....

    Alexey
    Alexey Smirnov, Jun 10, 2008
    #4
    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. Sam
    Replies:
    0
    Views:
    370
  2. A.M

    DropdownList and DataValue

    A.M, May 21, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    3,434
    Steven Cheng[MSFT]
    May 26, 2004
  3. AtomicBob
    Replies:
    14
    Views:
    857
    Toby Inkster
    May 2, 2006
  4. l7alabeh
    Replies:
    4
    Views:
    2,610
    l7alabeh
    Sep 20, 2006
  5. Sound
    Replies:
    2
    Views:
    427
    Randy Webb
    Sep 28, 2006
Loading...

Share This Page