Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linq to SQL Where ControlParameter for text in dropdownlist

Posted on 2010-08-21
7
Medium Priority
?
1,200 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
Amazon Web Services EC2 Cheat Sheet

AWS EC2 is a core part of AWS’s cloud platform, allowing users to spin up virtual machines for a variety of tasks; however, EC2’s offerings can be overwhelming. Learn the basics with our new AWS cheat sheet – this time on EC2!

 
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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

664 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