Solved

Add all to dropdownlist with datasource

Posted on 2008-10-04
10
1,054 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to connect to a remote mysql server using C#? 9 43
Asp.net mvc entity issue 6 20
Problem to page 4 27
Entity Framework 3 14
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now