Internet Engineer
Internet Engineer

Reputation: 2534

Linq to Entities and Drop Downs

I am loading the values into a drop down using linq to entities.

I need the first value in the drop down to read "Select" with value of 0 or "".

How can I add that value to my linq query or to the drop down in asp.net forms.

My current code:

    'Payment Types
    Dim SourcePaymentTypes = (From s In db.PayoutAdjustmentTypes.OrderBy("Name") Select s).ToList
    CmbReason.DataSource = SourcePaymentTypes
    CmbReason.DataTextField = "Name"
    CmbReason.DataValueField = "AdjustmentTypeID"
    CmbReason.DataBind()

Upvotes: 0

Views: 23

Answers (1)

dougajmcdonald
dougajmcdonald

Reputation: 20047

You need to .Add() a new PayoutAdjustmentType { Name = "Select", AdjustmentTypeId = 0 } record to your SourcePaymentTypes variable before you set it as the DataSource of your CmbReason

(Apologies it's in C# syntax, but I'm sure you can translate)

Upvotes: 1

Related Questions