Solved

Add all to dropdownlist with datasource

Posted on 2008-10-04
10
1,058 Views
Last Modified: 2012-08-14
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?
0
Comment
Question by:johnywhite
10 Comments
 
LVL 16

Expert Comment

by:anoyes
ID: 22642153
Can you post the code that you're using to bind the drop down list?
0
 

Author Comment

by:johnywhite
ID: 22642241

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

Open in new window

0
 
LVL 9

Expert Comment

by:HeoQue
ID: 22642362
please post the code-behind page ...
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:johnywhite
ID: 22642417
There is no code behind at this point. That is exactly how the data is bound to the control.
0
 

Author Comment

by:johnywhite
ID: 22642423
The only code-behind that exists at this point in the project is the empty method:
  protected void ddlSortBy_SelectedIndexChanged(object sender, EventArgs e)
    {
    }
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22642450
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

0
 

Author Comment

by:johnywhite
ID: 22642452
No there is no query. This is a linqdatasource the connects directly to the tables.
0
 

Author Comment

by:johnywhite
ID: 22953835
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.Employee.name, s.sid} Distinct)

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

        End If
    End Sub
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 22981140
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question