Last active
December 16, 2015 05:19
-
-
Save stevebosworth/5383859 to your computer and use it in GitHub Desktop.
A custom Databound Dropdownlist using LINQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="databoundHybridControl.aspx.cs" Inherits="databoundHybridControl" %> | |
<%@ Register TagPrefix="DBadvHC" Namespace="databoundHybrid" %> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"> | |
<title></title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<div> | |
<DBadvHC:hybridControlDB ID="hcDB_main" runat="server" /> | |
</div> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web.UI;//imported | |
using System.Web.UI.WebControls;//imported | |
using System.Linq; //imported | |
/// <summary> | |
/// Summary description for databoundHybridControl | |
/// </summary> | |
namespace databoundHybrid | |
{ | |
public class hybridControlDB : CompositeControl | |
{ | |
productClass objProd = new productClass(); | |
private DropDownList _ddlProducts; | |
protected override void CreateChildControls() | |
{ | |
//DropDownList | |
_ddlProducts = new DropDownList(); | |
_ddlProducts.ID = "ddl_products"; | |
_ddlProducts.DataSource = objProd.getProducts(); | |
_ddlProducts.DataTextField = "name"; | |
_ddlProducts.DataBind(); | |
this.Controls.Add(_ddlProducts); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
/// <summary> | |
/// Summary description for productClass | |
/// </summary> | |
public class productClass | |
{ | |
LinqClassDataContext objProdDC = new LinqClassDataContext(); | |
public IQueryable<product> getProducts() | |
{ | |
var allProducts = objProdDC.products.Select(x => x); | |
return allProducts; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment