all groups > asp.net datagrid control > november 2004 >
You're in the

asp.net datagrid control

group:

Display multiple fields in a drop down list in datagrid


Display multiple fields in a drop down list in datagrid et
11/30/2004 8:52:30 PM
asp.net datagrid control:
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

Re: Display multiple fields in a drop down list in datagrid Ken Cox [Microsoft MVP]
12/1/2004 4:03:56 PM
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]


[quoted text, click to view]
Re: Display multiple fields in a drop down list in datagrid Rock
12/2/2004 2:09:49 PM
That Works! Thanks

[quoted text, click to view]

Re: Display multiple fields in a drop down list in datagrid Ken Cox [Microsoft MVP]
12/2/2004 8:04:21 PM
Thanks for reporting back!

[quoted text, click to view]
AddThis Social Bookmark Button