Solved

Add all to dropdownlist with datasource

Posted on 2008-10-04
10
1,060 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

752 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