Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Linq to SQL Where ControlParameter for text in dropdownlist

Posted on 2010-08-21
7
Medium Priority
?
1,202 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
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 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

971 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