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

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

dropdownlist LINQ to SQL

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

Hi there,

I'm trying to populate a dropdonlist after a postback in a footer of a gridview, I've been copyng so many examples where they say to do it this way but  I keep gettin' exception when databinding why?

private void FillGrupos(int Category)
            Sports.Data_Access.MyDataContext db = new Sports.Data_Access.MyDataContext();

            var groups = from gr in db.tblGrupo
                         where gr.CatId == Category
                         orderby gr.Group descending
                         select new
                             GroupId = gr.GroupId,
                             Group = gr.Group,

            DropDownList ddl = (DropDownList) GridView1.FooterRow.FindControl("DropDownListFooterGroup");
            ddl.DataSource= groups;
            ddl.DataTextField = "Group";
            ddl.DataValueField = "GroupId";


View Complete Post

More Related Resource Links

Cascading DropDownList with LINQ

My application includes a gridview control with and Edit mode which allows users to do selections using cascading dropdownlist. My code is based on tutorial by Brian Orrell (link below). I am able to statically populate the dropdownlist but in my case I need to populate it dynamically based on a previous selection of a dropdownlist, I would like to do it programatically so I can manipulate data. I Could not find any code samples which show how to do it progamatically if anybody knows of a site with such example please post a link   http://borrell.parivedasolutions.com/2008/01/objectdatasource-linq-paging-sorting.html

linq - delete dropdownlist

My code:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"DataSourceID="LinqDataSource1" DataTextField="UserId" DataValueField="UserId"></asp:DropDownList>BurnbetDataDataContext db = new BurnbetDataDataContext();        var selectedID = (DropDownList1.SelectedValue);        tbl_Payment toDelete = db.tbl_Payments.Single(p => p.UserId == selectedID);        db.tbl_Payments.DeleteOnSubmit(toDelete);        db.SubmitChanges();Error:System.InvalidOperationException was unhandled by user code  Message=Sequence contains more than one element  Source=System.Data.Linq  StackTrace:       at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)       at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)       at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IPr

LINQ how to get data from dropdownlist in label1


            var dnevnice = from p in db.tbl_dnevnices
                         select p.Drzava;

            ddlDnevnice.DataSource = dnevnice;

I have label1.text.

Example: ID

How to display data according to the selected data in DropDownList?

Help: populate Html.DropDownList from table data? [Linq to SQL model]


I have two tables, Users and Roles.  The roles table is a reference table for the different roles of my site (RoleId and RoleName columns). The Users table contains profile data for each user, including a RoleId column that is FK'd back to the Roles table [RoleId].

Both tables are in a Linq to SQL model.

I have an edit page created which lists all the profile values of a user.  The edit page inherits the User model.  One of the editable values is the RoleId field.  I want to set this up to be a drop-down list that contains items labeled using the RoleName column of the Roles table, and matched with values of RoleId.

How can I achieve this?

How to get two data in dropdownlist with Linq


var customers = from c in db.tbl_relacije_sifrants
                        select new

        ddlRelacijeSifrant.DataSource = customers;
        ddlRelacijeSifrant.DataTextField = "Relacija";
        ddlRelacijeSifrant.DataValueField = "ID";

I need Two Pieces of data and the DropDownList.

Relationship + SifraId = DropDownList

What do I do?


Playing with Linq grouping: GroupByMany?

One of its features is grouping. Many people understand grouping like it is defined in Sql. Linq is implementing grouping quite the same way. Let's discover this syntax and how to make consecutive groups easier.

LINQ : Implementing IN and NOT IN

I got tried of typing

var result = from s in source
where items.Contains(s)
select s;and so I implemented the IN and NOT IN methods as extension methods:

101 LINQ Samples Tutorials

101 LINQ Example with sample code snippets....This sample prints each element of an input integer array whose value is less than 5. The sample uses a query expression to create a new sequence of integers and then iterates over each element in the sequence, printing its value

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.

Linq to Sql CompiledQuery container

Ok now let's go. Here is just a little trick but with some interesting patterns that could be useful in some other contexts not connected to Linq to Sql.

When using Linq expressions, like with Linq to Sql, translating the expression into something else (sql for example) is taking time and resources. Sometimes it's negligible, sometimes not...

LINQ to SQL Paging using GridView in C# and ASP.NET 3.5

This tutorial will show you how we can extend the LINQ to SQL Class and create methods that will allow us to page data from a SQL database. C# version.

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:

How to create 3 tier application using LINQ

As you know that in 3 tier architecture there are three layers

User interface layer. (Is our Form in Windows application and .aspx page in Web application)
Data Access layer. (Which provides interface between Business logic layer and Database)
Business Logic layer.(Which stores your application logic)

Building a LINQ Provider

Throughout this article, we will build a simple IQueryable provider similar to the LINQ to SQL provider demonstrating what is needed to build a custom provider that is capable of executing LINQ queries and performing create, update and delete operations.

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.
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