""Steven Cheng"" wrote:
> Hi Chuck,
>
> As for GridView, the automatic sorting has encapsulated the internal code
> logic. For your scenario, if you want to set initial sorting or
> programmatically adjust the sorting later, you can consider call the
> GridView.Sort method in GridView's PreRender event.
>
> The reason we use "PreRender" event is because at that time, the GridView
> has finished all other processing(such as the data loading or default
> sorting behavior) and you can do your own customization(and the change will
> be stored into viewstate). here is a simple example:
>
> #set initial sorting(when not postbacak) for the last column in GridView
> ==============
> protected void GridView1_PreRender(object sender, EventArgs e)
> {
> if (!IsPostBack)
> {
> GridView1.Sort(GridView1.Columns[5].SortExpression,
> SortDirection.Descending);
> }
> }
> ===========
>
> here is a good blog article about using LINQ DataSource and Gridview on
> scottgu's weblog:
>
> #LINQ to SQL (Part 5 - Binding UI using the ASP:LinqDataSource Control)
>
http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding > -ui-using-the-asp-linqdatasource-control.aspx
>
> Sincerely,
>
> Steven Cheng
>
> Microsoft MSDN Online Support Lead
>
>
>
> ==================================================
>
> Get notification to my posts through email? Please refer to
>
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif > ications.
>
>
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
>
http://msdn.microsoft.com/subscriptions/support/default.aspx. >
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
>
> --------------------
> >Thread-Topic: GridView LinqDataSource Sorting
> >thread-index: Ach5lrhidD2TpHnTTzSEsurxCvFMTA==
> >X-WBNR-Posting-Host: 128.165.159.58
> >From: =?Utf-8?B?Q2h1Y2sgUA==?= <Chuck@newsgroup.nospam>
> >Subject: GridView LinqDataSource Sorting
> >Date: Wed, 27 Feb 2008 15:16:02 -0800
>
> >
> >I don't know how the GridView does automagic sorting when using the
> >LinqDataSource.
> >
> >I would like to do two things.
> >
> >1. Set the inital sort order (State ASC)
> >2. Modify the sort when someone clicks on a colum
> > (e.g. someone clicks on state, set the sort to State DESC, Town ASC)
> >
> >
> >I can do 1. by
> > PageLoad()
> > if (!IsPostBack) GridView_Ex1.Sort("State",SortDirection.Ascending);
> >but I don't know if that is the best way.
> >
> >I looked at LinqDataSource1_Selecting, but didn't see anything in the
> >OrderBy parameter collection even when I was doing a column sort.
> >
> >Also I don't know how to do number 2.
> >
>