Solved

Linq to SQL Where ControlParameter for text in dropdownlist

Posted on 2010-08-21
7
1,185 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

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!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

740 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