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


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Binding Gridvew Using LINQ

Posted By:Athira Sreejith       Posted Date: December 31, 2008    Points: 10    Category: SQL Query    URL: http://www.dotnetspark.com  
 

Binding GridView using LINQ in asp.net. This is the sample code which will be helpful to understand how to bind the GridView using LINQ.

your Design Page:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">

Employee Details




PageIndex="10" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
CellPadding="4" ForeColor="Black" GridLines="Vertical" Width="100%"
onpageindexchanging="gvEmployee_PageIndexChanging">














Code behind:


using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindGrid();
}

private void BindGrid()
{
VetcareDataContext vetcare = new VetcareDataContext();
var Employee = from e in vetcare.Pay_Employees orderby e.Name select e;
gvEmployee.DataSource = Employee;
gvEmployee.DataBind();
}
protected void gvEmployee_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvEmployee.PageIndex = e.NewPageIndex;
BindGrid();
}
}


 

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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