Bind Linq convert Datatable to bind Gridview

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 1082
I have Post the Code
Bind Linq convert Datatable to bind Gridview
======================================================

DataClassesDataContext dtc = new DataClassesDataContext();
void BindGrid()
{
var result = dtc.Employees.ToList();
DataTable dt1 = new DataTable();
dt1.Columns.Add("Id");
dt1.Columns.Add("name");
DataRow dr;
foreach (var cat in result)
{
dr = dt1.NewRow();
dr[0] = cat.Id;
dr[1] = cat.name;
dt1.Rows.Add(dr);
}
grd1.DataSource = dt1;
grd1.DataBind();
}

Comments or Responses

Login to post response