Click here to Skip to main content
11,567,143 members (49,510 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB ASP.NET
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 21-Jan-13 16:49pm
Comments
Nandakishorerao at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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()
 

  Permalink  

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

  Print Answers RSS


Advertise | Privacy | Mobile
Web04 | 2.8.150624.2 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100