Click here to Skip to main content
14,767,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table

name dept area
mr.a IT s/w
mr. b IT H/w
mr.c Admin Admin

i am trying to data bind drop down list box

like

mr.a - it
mr. b - it
mr.c - Admin



i tried to have

dropdownbox.DataSource = ds
dropdownbox.DataValueField = "name"
dropdownbox.DataTextField = "name" & " - " & "dept"
dropdownbox.DataBind()

but it shows error

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'name - dept'

please help me
Posted
Comments
Nandakishore G N 21-Jan-13 23:02pm
   
you cannot add the fields to datatextfield..better you prepare other column in your dataset with concating the "name"-"dept"..and then bind..it to dropdownlist..

1 solution

Hi,

In your SQL query itself you do some changes .
please check the below query

SELECT name,dept,name+' - ' +dept AS DETAILS FROM TABLE_NAME


AFTER write this query then bind the table like this.

dropdownbox.DataSource = ds
dropdownbox.DataValueField = "name"
dropdownbox.DataTextField = "DETAILS"
dropdownbox.DataBind()
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900