Solved

Add all to dropdownlist with datasource

Posted on 2008-10-04
10
1,059 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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 …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 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