Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-10
8
Medium Priority
?
354 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 64

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 64

Expert Comment

by:Fernando Soto
ID: 22687172
On which line of code did you get this on?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 64

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 64

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

609 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