Solved

Linq to SQL Where ControlParameter for text in dropdownlist

Posted on 2010-08-21
7
1,179 Views
Last Modified: 2013-11-11
Hi EE,

I have an asp page with 4 dropdownlists (DD) and a grid.  When a user selects a dropdown(DD)  it automatically fills the next  DD according to the selectedvalue.
Everything works fine when using the selected value, but on my last DD I have to take the text from the 3rd DD to filter the last DD.
For example, the 3rd DD has a list with CityID and  CityName, instead of filtering the last DD by CityID, I need to match the CityName field with the SalonCity field in the last DD.
How would I do this using Linq to SQL?
Thanks
<td>    

                         <asp:DropDownList ID="ddCity" Width="95%"  runat="server" AutoPostBack="True" 

                              DataSourceID="DSCities" DataTextField="CityName" 

                              DataValueField="CityLUID">

                         </asp:DropDownList>                                

                         <asp:LinqDataSource ID="DSCities" runat="server" 

                              ContextTypeName="SalonClassesDataContext" OrderBy="CityName" 

                              Select="new (CityLUID, CityName)" TableName="CitysLUs" 

                              Where="StateID == @StateID">

                              <WhereParameters>

                                   <asp:ControlParameter ControlID="ddState" Name="StateID" 

                                        PropertyName="SelectedValue" Type="Int32" />

                              </WhereParameters>

                         </asp:LinqDataSource>

                    </td>

                    <td>

                         <asp:DropDownList ID="ddSalonName"  Width="95%" runat="server" 

                              AutoPostBack="True" DataSourceID="DSSalonNames" DataTextField="SalonName" 

                              DataValueField="StylistID">

                         </asp:DropDownList>                                

                         <asp:LinqDataSource ID="DSSalonNames" runat="server" 

                              ContextTypeName="SalonClassesDataContext" OrderBy="SalonName" 

                              Select="new (StylistID, SalonName)" TableName="Stylists" 

                              Where="SalonCity == @CityName">

                              

                              <WhereParameters>

                                   <asp:ControlParameter ControlID="ddCity" Name="CityName" 

                                        PropertyName="SelectedItem" Type="String" />

                              </WhereParameters>

                         </asp:LinqDataSource>

                    </td>

Open in new window

0
Comment
Question by:Sheritlw
  • 5
  • 2
7 Comments
 
LVL 27

Expert Comment

by:nmarun
ID: 33493898
Haven't tried this, but give this a shot:                                                                                                         PropertyName="SelectedItem.Text" Type="String" />                              Arun
0
 
LVL 27

Expert Comment

by:nmarun
ID: 33493903
not sure why it posted incorrectly. Second trial.Arun
<WhereParameters>

    <asp:ControlParameter ControlID="ddCity" Name="CityName" 

         PropertyName="SelectedItem" Type="String" />

</WhereParameters>

Open in new window

0
 
LVL 27

Expert Comment

by:nmarun
ID: 33493904
                PropertyName="SelectedItem.Text" Type="String" />
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 27

Expert Comment

by:nmarun
ID: 33493910
Ok.. my final answer is the first post.Arun
0
 

Author Comment

by:Sheritlw
ID: 33493928
Unfortunately It didn't work.
0
 
LVL 27

Accepted Solution

by:
nmarun earned 500 total points
ID: 33494386
That's strange, cos I have a similar piece that is working.

Arun

<asp:DropDownList ID="ddList" runat="server" AutoPostBack="True" />

<br />

<asp:LinqDataSource ID="DSCities" runat="server" TableName="Products" 

    Where="Name == @Name" 

    ContextTypeName="WebApplication1.SportsStoreDataContextDataContext">

    <WhereParameters>

        <asp:ControlParameter ControlID="ddList" Name="Name" PropertyName="SelectedItem.Text"

            Type="String" />

    </WhereParameters>

</asp:LinqDataSource>

<br />

<asp:DropDownList ID="ddSalonName" Width="95%" runat="server" DataSourceID="DSCities" 

     DataTextField="Category" DataValueField="ProductID">

</asp:DropDownList>



// code-behind:

protected void Page_Load(object sender, EventArgs e)

{

    if (!IsPostBack)

    {

        string conxnString =

            ConfigurationManager.ConnectionStrings["SportsStoreConnectionString"].ConnectionString;

        SportsStoreDataContextDataContext sportsStoreDataContextDataContext =

            new SportsStoreDataContextDataContext(conxnString);

        ddList.DataSource = sportsStoreDataContextDataContext.Products;

        ddList.DataTextField = "Name";

        ddList.DataValueField = "ProductID";

        ddList.DataBind();

    }

}

Open in new window

0
 

Author Comment

by:Sheritlw
ID: 33524961
I see, I would need to add some additional code to get that to work.

Thanks
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

14 Experts available now in Live!

Get 1:1 Help Now