ASP.NET LINQ Articles

LINQ Gridview Operation

Good links to learn LINQ for beginner

http://www.codeproject.com/KB/linq/LINQNewbie.aspx

http://www.codeproject.com/KB/linq/LINQquery.aspx

http://www.codeproject.com/KB/linq/LINQFAQPart2.aspx

Get Data using Stored procedure in gridview

var Emp = db.GetEmployeeByID(10);

GridView1.DataSource = Emp;

GridView1.DataBind();

foreach (var item in Emp)

{

string strName = item.Name;

string Designation = item.Designation;

string Department = item.Department;

string Salary = item.Salary;

}

Display Specific column Name in gridview

NorthwindDataContextDataContext db = new NorthwindDataContextDataContext();

var cust = (from p in db.Customers

where p.CustomerID == “test”

select new

{

ID = p.CustomerID,

Name = p.ContactName,

Phone = p.Phone

}

);

GridView1.DataSource = cust;

GridView1.DataBind();

Calculation of price in Gridview

NorthwindDataContextDataContext db = new NorthwindDataContextDataContext();

var product = (from p in db.Products

where p.CategoryID == 1

select new

{

ProductName = p.ProductName,

Total = p.Order_Details.Count,

Revenu = p.Order_Details.Sum(o=>o.UnitPrice * o.Quantity)

}

);

GridView1.DataSource = product;

GridView1.DataBind();

Gridview Paging

protected void Page_Load(object sender, EventArgs e)

{

int intPageNumber = Convert.ToInt32(Request.QueryString["StartRow"]);

BindGridviewView(intPageNumber);

}

public void BindGridviewView(int StartRow)

{

NorthwindDataContextDataContext db = new NorthwindDataContextDataContext();

var Customers = (from p in db.Customers

select new

{

Name = p.ContactName,

Phone =p.Phone,

Fax = p.Fax

}

);

GridView1.DataSource = Customers.Skip(StartRow).Take(10);

GridView1.DataBind();

}

USE [ControlLibrary]
GO
/****** Object:  Table [dbo].[cms_contentdetails]    Script Date: 01/13/2010 09:07:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[cms_contentdetails](
[intContentDetailId] [int] IDENTITY(1,1) NOT NULL,
[intNodeID] [int] NULL,
[txtDefaultURL] [varchar](500) NULL,
[flgCustomURL] [int] NULL,
[txtCustomURL] [varchar](500) NULL,
[txtTitle] [varchar](500) NULL,
[txtMetaKeyword] [text] NULL,
[txtMetaDescription] [text] NULL,
[txtMainContent] [text] NULL,
[flgPublish] [int] NULL,
[flgDeleted] [int] NULL,
[txtCreatedBy] [varchar](50) NULL,
[dtDateCreated] [datetime] NULL,
[txtModifiedBy] [varchar](500) NULL,
[dtDateModified] [datetime] NULL,
[txtPageName] [varchar](500) NULL,
[txtNodeName] [varchar](500) NULL,
[intNodeParentID] [int] NULL,
[intNodeOrder] [int] NULL,
[flgActive] [int] NULL,
CONSTRAINT [PK_cms_contentdetails] PRIMARY KEY CLUSTERED
(
[intContentDetailId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET ANSI_PADDING OFF

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Tag Cloud

Follow

Get every new post delivered to your Inbox.