dropdownlist's Datavaluefield is not working

Posted by Ranjana on Stack Overflow See other posts from Stack Overflow or by Ranjana
Published on 2011-01-08T16:43:01Z Indexed on 2011/01/08 16:53 UTC
Read the original article Hit count: 133

Filed under:
|

i am getting the datas from database and storing in a collectionobject. The collectionobj contains the Datas 'Name' and 'ID'.

My code:

<asp:dropdownlist id="dropdown1" runat="server" DataTextField="Name" DataValueField="ID"/>


collectionobj=objbs.GetNAmes()

for intloop as integer in Collectionobj.Count.Rows-1 

dropdown.Items.Add( Collectionobj.Items(intloop).Name)
dropdown.DataValueField=Collectionobj.Items(intloop).ID

Next
dropdown.DataBind()

Im getting the Value binded in the dropdown as "Names" . when i select the dropdown i need to pass the respective ID of that name.

But when I assign the

Dim strid as String=dropdown1.DataValueField

The dropdown1.DataValueField is holding the id of last name binded in the dropdown.it is not taking the id which im selecting n the dropdown..

Any suggestion..........

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about dropdownlist