.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Help tloading a dropdownlist using lambda expression??? o/

Posted By:      Posted Date: October 13, 2010    Points: 0   Category :ASP.Net

Hello everyone

Thank you for your time..

I´m trying to load one field from the table using Lambda

 public void Search()


            ddlcity.DataSource = companiesBLL.Find(e => e.city.Equals(e.ID_COMPANY)).ToList();



ddlcity = dropdown

id_city = main Id (primarykey of that table)

but i want to only load the city field from the table Company.

I´d appreciate if anyone could help me.


 public void Bairro()
            ddlBairro.DataSource = empresasBLL.Find(e => e.BAIRRO.Equals(e.ID_EMPRESA)).ToList();

View Complete Post

More Related Resource Links

Implicit-type lambda expression: is it possible?

Hi all, i was plaing around with LINQ and lambda expressions. I was trying to find duplicated files in my system. After a while a realized that duplicated could mean: - same name - same size and extension - ....   So i wrote this code: DirectoryInfo rootDirectory = ....; var groupFiles = selector => rootDirectory.EnumerateFiles("*", SearchOption.AllDirectories).GroupBy(selector).Select(g => new { g.Key, Info = g, Count = g.Count() }).Where(g => g.Count > 1); var groupsByName = groupFiles(f => f.Name); var groupsBySize = groupFiles(f => new { f.Length, f.Extension}); But i get the following error: Error 1 Cannot assign lambda expression to an implicitly-typed local variable So i tryed to make the type explicit and i realized that is not so easy. So what i'm missing?! IMPORTANT. 'm not tying to have the code working. I can solve the issue by duplicating code (even if i hate to do that) I'm rtying to improve my skills with LINQ and Lambda Expressions. Thanks all!!  

RenderAction with Lambda Expression in MVC 3.0 preview 1


Hi all, i have the following, which works:

@{Html.RenderAction("Detail", "Help", new { pageName = "press" });}

But instead i'd like to use a lambda expression to get away from the string bits. I tried using the following (which is the nearest approximation i could figure based on my limited knowledge of the engine):

@{Html.RenderAction<HelpController>(x => x.Detail("press"));}

But i get the following error:

The non-generic method 'System.Web.Mvc.Html.ChildActionExtensions.RenderAction(System.Web.Mvc.HtmlHelper, string, string, System.Web.Routing.RouteValueDictionary)' cannot be used with type arguments

However, i'm reading in the Apress MVC 2.0 book that it is in fact declared as a method that takes type arguments. Am i missing an assembly reference, or has it not been included in the MVC 3.0 Preview 1 build?

Lambda expression


Hi guys,

Anybody please give me the example How to use Lambda expression in linq.please give a simple example and describe it also.


How to create a generic Lambda Expression


I Use entity framework 4.

Here is my model






Each time I want the text for one of these model, I execute this lambda expression p=> p.LangID == 1

Is it possible to create a generic lambda expression function that all of these model can use.?

How to use lambda expression to replace if-else


I have a list of possible nodes as a child of parent node, i need to compare the nodeName and if node name matches, i need to get the value and assign it to member variable.

public class Contacts
private string FirstName;
private string LastName;
  public LoadContacts(XmlNode contactNode)
    string[] names={
    foreach(XmlNode child in contactNode)
     if( child.Name == names[0])
       m_firstName = child.Value;
     if(child.Name == names[1])
       m_lastName = child.Value;

Is there a way of re-factor the same code with Lambda expression.

Thanks in Advance.


DRY with Lambda Expression (errors management)


In my current project, I have made a miracle with Lambda Expression. Have you ever implemented something like this:

    public abstract class GenericRepository<TEntity> : IRepository<TEntity> where TEntity : classIEntity
        private readonly ILog _logger;

        protected GenericRepository()
            : this(IoC.GetInstance<IUnitOfWork>(), IoC.GetInstance<ILog>()

Linq: how to share parameters between lambda expressions ?

When using Linq to objects, you will quickly feel the need to pass some parameters from a method to another but it's not so easy because each Linq method is not calling the following one. In a Linq sequence, each method is using the result computed by the previous one. So, local contexts are not visible from one method to another.
The compiler is using two technical different ways to let parameters go out of a method.

jQuery: Styling DropDownList Alternating Items (Rows)

In the following example, I will show how you can style any asp:dropdownlist very easily.

The example demonstrates how you can change alternating row items background color, using the fadeTo() to add a nice touch in the dropdownlist. You can change alt rows with a couple lines.

What is Lambda Expressions In LINQ

A lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.

All lambda expressions use the lambda operator =>, which is read as "goes to". The left side of the lambda operator specifies the input parameters (if any) and the right side holds the expression or statement block. The lambda expression x => x * x is read "x goes to x times x." This expression can be assigned to a delegate type as follows:

Working with DropDownList and ListBox Controls in ASP.NET

"In my application i am using dropdownlist to display all categories from a table. When the user clicks this control I display all records in that category. Category table also contains column called color.

I wanted display some categories in dropdown list different color and others in different color using ASP.NET."-Anonymous

ASP.NET DropDownList Web Control, Part 1

Anybody with much experience in ASP has written an include file function for populating the contents of a SELECT dropdown list with entries from a database. Some of the more advanced users have even gone so far as to add caching to their function to reduce database hits for these rarely changing menu options. Naturally, these same techniques are going to be used with ASP.NET, but with a new programming object model. ASP.NET provides a web control, the DropDownList, which can be used for the same purposes as our custom built SELECT tag from Classic ASP.

Declaring a DropDownList in ASP .Net

A DropDownList is also commonly known as combo box. It can contain multiple data members, but unlike a normal list box the users can choose only one value from this control. Though the functionality of this DropDownList is much like a Single Row Select List Box, a DropDownList can save a lot of GUI space as it is rendered on a Single line and is expanded only when the user clicks on the Control

Multiple Column Dropdownlist for the ASP.NET DataGrid

Based on my previous control "Multiple Column DropDownList for ASP.NET", I received many emails asking for the same control to be used in the DataGrid for web applications. Here we go.. This control can be used as the regular MS DropDownList in the DataGrid and also as a regular dropdownlist. It has all the properties, like DataTextField, DataValueField, DataSource, SelectedIndex etc. The download file contains the samples both in VB.NET and C#. In this sample, I have used the Northwind database of SQL Server.

ASP.NET Multiple Selection DropDownList with AJAX HoverMenuExtender

Recently, I was looking for a multiple selection dropdownlist control for my new project. After spending some time researching for it, I decided to put together all my finding in one web user control. This web user control consists of an ASP.NET AJAX HoverMenuExtender, JavaScript, StyleSheet and CheckBoxListExCtrl . The final product will work with or without a MasterPage and you can drag and drop more than one instances of the control on to the page.

How to bind GridView and DropDownList controls using DataTable object

In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.

How to bind TemplateField DropDownList with ArrayList?


Hi Expert!

  I'm trying gridview templateField DropDownList bind with arraylist. When i set bindsource i got this error. "//Error Object reference not set to an instance of an object."

My Sample .aspx

<asp:TemplateField HeaderText="Type">
                        <asp:DropDownList ID="_grvcboType" runat="server" Width="117px" DataTextField="Display" DataValueField="Value">
                        <asp:Label ID="Label7" runat="ser

how to make a dropdownlist looks like google search box


dear all...

any idea how to do that ?

Thnx in advance

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend