Solved

Arrays with linq to sql and how to use them with ajax CascadingDropDownNameValue method

Posted on 2008-10-10
8
317 Views
Last Modified: 2013-12-17
How can I use linq to sql to populate ajax dependant dropdown?

I need to pass a collection into the dropdown method so am trying to do something like this

List<AjaxControlToolkit.CascadingDropDownNameValue> cascadeCollection = new List<AjaxControlToolkit.CascadingDropDownNameValue>();


//linq
 var items = from p in dc.categories
                    where p.categoryID == 1
                    select p.categoryID + p.categoryDescription ;

string[] names = items.ToArray();

However I need to pass the "categoryDescription " and "categoryDescription " to CascadingDropDownNameValue

essentially I need to iterate through categories collection and add pass   p.categoryID ,  p.categoryDescription

how can I do this or what is a better approach?




0
Comment
Question by:mugsey
  • 4
  • 4
8 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 22686560
Hi mugsey;

I am not a web developer but with that said I believe that the query below is all that you may need. There is no need to turn the results to an array of strings all that may be needed is to assign the query items to the data source of the control.

Fernando


//linq

IEnumerable<AjaxControlToolkit.CascadingDropDownNameValue> items = 

        from p in dc.categories

        where p.categoryID == 1

        select new AjaxControlToolkit.CascadingDropDownNameValue

        {

            p.categoryDescription,

            p.categoryID   

        };

Open in new window

0
 

Author Comment

by:mugsey
ID: 22686900
Hi Thanks Fernando

I did try that but I do get error

'System.Linq.IQueryable<itemcategory>' to 'System.Collections.Generic.IEnumerable<AjaxControlToolkit.CascadingDropDownNameValue>'. An explicit conversion exists (are you missing a cast?)      
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 22687172
On which line of code did you get this on?
0
 

Author Comment

by:mugsey
ID: 22687604
Hi Sorry in fact I get this error on the opening parenthisis

Cannot initialize type 'AjaxControlToolkit.CascadingDropDownNameValue' with a collection initializer because it does not implement 'System.Collections.IEnumerable'      

{
            p.categoryDescription,
            p.categoryID  
        };
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.

 

Author Comment

by:mugsey
ID: 22687883
Ahh seems to work as took out parenthisis and put in ()

it compiles
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 22688057
Glad It worked out I was just about to try and build a small project to see what was going on. ;=)
0
 

Author Comment

by:mugsey
ID: 22688211
Ahh having said that it does not iterate through the collection - would it be possible for you to get a prototype working please?
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 22694355
I am sorry I attempted to create a small website using the Ajax controls but as I stated in my first post I am not a web developer and could not find the info needed to create a Ajax page with the 3.5 .Net Framework with the controls so that I could test the linq part.

You can place a question with community support to reopen this question and hopefully someone with ASP .Net know how can answer your question.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

16 Experts available now in Live!

Get 1:1 Help Now