Solved

Linq to SQL Where ControlParameter for text in dropdownlist

Posted on 2010-08-21
7
1,180 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

912 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

18 Experts available now in Live!

Get 1:1 Help Now