sorting in gridview using linq.........
-
Hi, I am new to linq and using it for the first time. I am stuck up in the middle of the project. I want to do sorting in gridview using LINQ. Can anyone help me out.Can anyone provide me the sample code or any useful link to do this. I have done a lot of googling ,but enable to find perfect solution to this. here is the sample code which i have used to bind gridview.
protected void BindGrid()
{
try
{
var employees = from e in DetailContext.Employees select new {e.Emp_Id,
e.Emp_Code, e.F_Name, e.L_Name, e.Designation };
GridView1.DataSource = employees;
GridView1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}Pranav Dave
-
Hi, I am new to linq and using it for the first time. I am stuck up in the middle of the project. I want to do sorting in gridview using LINQ. Can anyone help me out.Can anyone provide me the sample code or any useful link to do this. I have done a lot of googling ,but enable to find perfect solution to this. here is the sample code which i have used to bind gridview.
protected void BindGrid()
{
try
{
var employees = from e in DetailContext.Employees select new {e.Emp_Id,
e.Emp_Code, e.F_Name, e.L_Name, e.Designation };
GridView1.DataSource = employees;
GridView1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}Pranav Dave
where is orderby clause friend... orderby clause is used to order linq data objects. you can just add orderby e.F_Name to sort it on F_Name :rose::rose:
Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
Create .NET Templates -
where is orderby clause friend... orderby clause is used to order linq data objects. you can just add orderby e.F_Name to sort it on F_Name :rose::rose:
Abhishek Sur My Latest Articles Basics on LINQ and Lambda Expressions
Create .NET Templateshi abhishek, I totally agree with u.The order by clause is used to order the linq data. But my question is that there are some data displayed in gridview and i want to apply sorting and paging on gridview with the help of linq because i have bind the gridview with the help of linq.I have already applied paging on gridview but unable to apply sorting on gridview columns as we normally do with the help of dataset or dataview. i have already tried many ways and did lot of googling but still unable to find the solutions to apply sorting on gridview columns with the help of linq. If you could please suggest some solutions to me. regards, pranav
Pranav Dave
-
Hi, I am new to linq and using it for the first time. I am stuck up in the middle of the project. I want to do sorting in gridview using LINQ. Can anyone help me out.Can anyone provide me the sample code or any useful link to do this. I have done a lot of googling ,but enable to find perfect solution to this. here is the sample code which i have used to bind gridview.
protected void BindGrid()
{
try
{
var employees = from e in DetailContext.Employees select new {e.Emp_Id,
e.Emp_Code, e.F_Name, e.L_Name, e.Designation };
GridView1.DataSource = employees;
GridView1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}Pranav Dave
Hi, base one your code: protected void BindGrid() { try { var employees = from e in DetailContext.Employees select new {e.Emp_Id, e.Emp_Code, e.F_Name, e.L_Name, e.Designation }; GridView1.DataSource = employees; GridView1.DataBind(); } catch (Exception ex) { throw ex; } } you can add this from e in DetailContext.Employees orderby [columnfield] descending
Hope this one can help. Thanks Hi, Please select Good Question if my answer are fit to your Question.