get first and last datavalue field entry of dropdown box

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

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.
 
probably an easy way to do this but in the code behind I could not see howto
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.

Hi Paul

I think, you can use Items collection

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

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


Alexey Smirnov said:
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.

Hi Paul

I think, you can use Items collection

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

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



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
 
Back
Top