Solved

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

Posted on 2008-10-10
8
343 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
[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
  • 4
  • 4
8 Comments
 
LVL 63

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 63

Expert Comment

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

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

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
 

Author Comment

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

it compiles
0
 
LVL 63

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 63

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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