AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 Linq Query to sort in Column-Header in GridView
Posted by Rudolf Terppe on  12/19/2007 10:54:39 AM Category: ADO.NET
Add to my favorites
Email to friend
Hi,

I started new with Linq and created a new Web-App automatically with DataContext and LinqDataSource.
But, because I want to place the var LinqQuery into the CodeBehind-File, I code the Var LinqQuery by hand and not by designer.

That works well in GridView and DetailView with New, edit, delete and Paging
but for sorting I have no Idea with SortExpression and SortDirection inside of var LinqQuery

private string GridViewSortDirection{
get{return ViewState["SortDirection"] as string ?? "ASC";}
set{ViewState["SortDirection"] = value;}
}

private string GridViewSortExpression{
get{return ViewState["SortExpression"] as string ?? string.Empty;}
set{ ViewState["SortExpression"] = value;}
}

protected void gvMain_Sorting(object sender, GridViewSortEventArgs e)
{
GridViewSortExpression = e.SortExpression;
GridViewSortDirection = e.SortDirection.ToString();
int pageIndex = gvMain.PageIndex;
db = new CorydorasDataContext();

var FiArtsQuery = from p in db.FiArts
where p.Name.StartsWith(txtSuch.Text)
// orderby p.SortExpression SortDirection xxxxxxxxx ???
orderby p.Name descending
select p;
gvMain.DataSource = FiArtsQuery;
gvMain.DataBind();
gvMain.PageIndex = pageIndex;
}

I hope anybody can help me?
thanks


Rudolf

Post Your Reply Post New Question

 Viewer's Reply
This Question has 0 replies.

 
Sponsored by
The Beginner's Guide to Joomla
Introduction to Software Development
SearchSAP