?
Solved

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

Posted on 2008-10-10
8
Medium Priority
?
351 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 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

764 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