using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace lmproyectolinq { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //FillList(); using (ProductosDataContext context = new ProductosDataContext()) { //LINQ Query var query = from ct in context.Productos select ct.IdCategoría; if (query != null) { DropDownList1.DataSource = query.Distinct().ToList(); DropDownList1.DataBind(); FillList(); } } } } protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e) { Response.Write("<br/> "); if (DropDownList1.SelectedValue == "All") { e.WhereParameters.Remove("idCategoría"); } } protected void FillList() { DropDownList1.Items.Add(new ListItem("All", "All")); } } }