Add all to dropdownlist with datasource

I have a dropdownlist that is bound linqdatasource. The dropdownlist is used to only contacts based on a job type that is selected in the dropdown. It works perfectly, however, there are instances where the user wants an all option to display all contacts no matter what their job type. How do I add this and still use the datasource?
Who is Participating?
Computer101Connect With a Mentor Commented:
PAQed with points refunded (500)

EE Admin
Can you post the code that you're using to bind the drop down list?
johnywhiteAuthor Commented:

                    <asp:DropDownList ID="ddlSortBy" runat="server" 
                        onselectedindexchanged="ddlSortBy_SelectedIndexChanged" AutoPostBack="True" 
                        DataSourceID="datasourceCrafts" DataTextField="Craft" DataValueField="ID">
                    <asp:LinqDataSource ID="datasourceCrafts" runat="server" 
                        ContextTypeName="MDataClassesDataContext" OrderBy="Craft" 

Open in new window

The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

please post the code-behind page ...
johnywhiteAuthor Commented:
There is no code behind at this point. That is exactly how the data is bound to the control.
johnywhiteAuthor Commented:
The only code-behind that exists at this point in the project is the empty method:
  protected void ddlSortBy_SelectedIndexChanged(object sender, EventArgs e)
Anurag ThakurTechnical ManagerCommented:
If there is a Query selecting the JobType from the JobType table then modify it as follows

Select 'Text' = 'All', Valaue = '-1'
Union All
Select 'Text' = JobTypeName, 'Value' = JobID From JobTypeTable

johnywhiteAuthor Commented:
No there is no query. This is a linqdatasource the connects directly to the tables.
johnywhiteAuthor Commented:
I found the solution myself. If anyone finds this in the future here it is:
    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        If Not IsPostBack Then

            Dim dc As New QSSDataContext
            Dim Emps = (From s In dc.Shifts Where s.Employee.inActive Is Nothing OrElse s.Employee.inActive = False Select New With {, s.sid} Distinct)

            ddlSortBy.DataSource = Emps.OrderBy(Function(em)
            ddlSortBy.DataTextField = "name"
            ddlSortBy.DataValueField = "sid"
            ddlSortBy.Items.Insert(0, "All Employees")

        End If
    End Sub
All Courses

From novice to tech pro — start learning today.