Solved

Linq to SQL Where ControlParameter for text in dropdownlist

Posted on 2010-08-21
7
1,197 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
[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
  • 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
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!

 
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

622 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