Solved

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

Posted on 2008-10-10
8
309 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 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

12 Experts available now in Live!

Get 1:1 Help Now