Display multiple fields in a drop down list in datagrid

E

et

How would I display the value of multiple fields in a drop down list in a
bound datagrid. I tried changing the DataTextField to include both fields,
but received an error: ddl.DataTextField = "CountyName" & "CountyCode" to
display something like this:
"Burrough County (BC)"
This is my current code:
Dim qry As String = "SELECT CountyCode, CountyName from tblCounties"

Dim da As SqlDataAdapter = New SqlDataAdapter(qry, strConn)

Dim ds As New DataSet

Dim item As ListItem

da.Fill(ds, "tblCounties")

ddlCropCode.DataTextField = "CountyName"

ddlCropCode.DataValueField = "CountyID"

ddlCropCode.DataBind()



Can
 
K

Ken Cox [Microsoft MVP]

Hello,

I think you can solve this with your SQL SELECT query. Not sure of the exact
syntax but it would look something like this:

"SELECT CountyCode + '  ' + CountyName AS CountyInfo, CountyCode,
CountyName from tblCounties"

ddlCropCode.DataTextField = "CountyInfo"

Let us know if it works?

Ken
Microsoft MVP [ASP.NET]
 
R

Rock

That Works! Thanks

Ken Cox said:
Hello,

I think you can solve this with your SQL SELECT query. Not sure of the exact
syntax but it would look something like this:

"SELECT CountyCode + '  ' + CountyName AS CountyInfo, CountyCode,
CountyName from tblCounties"

ddlCropCode.DataTextField = "CountyInfo"

Let us know if it works?

Ken
Microsoft MVP [ASP.NET]


et said:
How would I display the value of multiple fields in a drop down list in a
bound datagrid. I tried changing the DataTextField to include both
fields,
but received an error: ddl.DataTextField = "CountyName" & "CountyCode"
to
display something like this:
"Burrough County (BC)"
This is my current code:
Dim qry As String = "SELECT CountyCode, CountyName from tblCounties"

Dim da As SqlDataAdapter = New SqlDataAdapter(qry, strConn)

Dim ds As New DataSet

Dim item As ListItem

da.Fill(ds, "tblCounties")

ddlCropCode.DataTextField = "CountyName"

ddlCropCode.DataValueField = "CountyID"

ddlCropCode.DataBind()



Can
 
K

Ken Cox [Microsoft MVP]

Thanks for reporting back!

Rock said:
That Works! Thanks

Ken Cox said:
Hello,

I think you can solve this with your SQL SELECT query. Not sure of the exact
syntax but it would look something like this:

"SELECT CountyCode + '  ' + CountyName AS CountyInfo, CountyCode,
CountyName from tblCounties"

ddlCropCode.DataTextField = "CountyInfo"

Let us know if it works?

Ken
Microsoft MVP [ASP.NET]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top