Jimsan
Jimsan

Reputation: 305

Dropdownlist populated with Linq to SQL not displaying items correctly - VB

I am populating a dropdownlist in the edititemtemplate of a formview using linq to SQL.

I am getting the data with the below code:

Dim wdc As New WeeklyChecksDataContext

        Dim mustchk = (From w In wdc.WeeklyChecks
                       Where w.DateStamp = Request.QueryString(0)
                  Select w.musterCheck).FirstOrDefault()

When debugging I can see that the value "Issue" is being assigned to the mustchk variable which is correct.

I am then databinding the dropdownlist as below:

cbMusterReport.DataSource = mustchk
            cbMusterReport.DataBind()

When running the web page the value "Issue" is databound to the dropdownlist but each letter of the word "Issue" is databound to its own separate item rather than the word "Issue" being databound as the only item in the dropdownlist. Can't work out what I am missing here. Thanks

Upvotes: 0

Views: 531

Answers (2)

Magnus
Magnus

Reputation: 46997

You need to put the string in a collection. Try this:

cbMusterReport.DataSource = new String(){ mustchk }
cbMusterReport.DataBind()

Upvotes: 1

Jimsan
Jimsan

Reputation: 305

Sorry, I've worked it out. Can do it like this

cbMusterReport.Items.Insert(0, New ListItem(mustchk, mustchk))

Upvotes: 0

Related Questions