vb.net - Convert dropdownlist value to string -


i have 2 tables in db, building , rooms. using 2 dropdownlists. aim have first dropdownlist, ddlbuilding, selecting building name. when name selected want query database find room numbers correspond building , return them in room dropdownlist, ddlroomnumber.
example:

building has rooms 1, 2 , 3.
building b has rooms 4, 5 , 6.

if user selects building ddlbuilding should presented rooms 1, 2 , 3 in ddlroomnumber

i have set query getting error dropdownlist cannot converted string. code in question is:

  protected sub txtroomnumber_textchanged(byval sender object, byval e system.eventargs) handles txtroomnumber.textchanged      dim db new oriondataclassesdatacontext      dim roomnumber = (from build in db.buildings join rm in db.rooms on build.building_code equals rm.building_code                       build.building_name = ddlbuilding                       select rm.room_number).distint      ddlroomnumber.datasource = roomnumber     ddlroomnumber.databind()  end sub 

it line where build.building_name = ddlbuilding causing error. thoughts on how can pull string out of dropdownlist , use validate query.

i have changed code follow after responses , research. still not working. ddlroomnumber not binding query.

protected sub ddlroomnumber_selectedindexchanged(byval sender object, byval e system.eventargs) handles ddlroomnumber.selectedindexchanged      dim db new oriondataclassesdatacontext       ddlroomnumber.datasource = (from build in db.buildings join rm in db.rooms on build.building_code equals rm.building_code                                 (build.building_name = ddlbuilding.selecteditem.text)                                 select rm.room_number, rm.room_id)      ddlroomnumber.datatextfield = "room_number"     ddlroomnumber.datavaluefield = "room_id"     ddlroomnumber.databind() end sub 

this asp page. there way type in linq datasource point vb query.

<asp:dropdownlist id="ddlroomnumber" runat="server" autopostback="true">                            </asp:dropdownlist> 

you can use ddlbuilding.selecteditem.text instead of ddlbuilding


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -