Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Because depending on the sort expression (which you defined in your markup) SqlDataSource will very likely do something <em>like</em> this (I'm not sure this is <em>exactly</em> what it does) for you behind the scenes:</p> <pre><code>Expression&lt;Func&lt;DataRow,object&gt;&gt; myExpression = row =&gt; row["SortExpressionYouDefinedForTheColumn"]; IEnumerable&lt;DataRow&gt; ex = ds.Tables[0].AsEnumerable().OrderBy(myExpression.Compile()); </code></pre> <p>Or <code>SqlDataSource</code> may be using a <code>DataView</code> to sort the <code>DataTable</code>.</p> <p>SqlDataSource can do this because by default it uses a DataSet to store the result set (<a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.datasourcemode.aspx" rel="nofollow">or so says the documentation</a>):</p> <blockquote> <p>The data retrieval mode identifies how a SqlDataSource control retrieves data from the underlying database.</p> <p>When the DataSourceMode property is set to the DataSet value, data is loaded into a DataSet object and stored in memory on the server. This enables scenarios where user interface controls, such as GridView, offer sorting, filtering, and paging capabilities..</p> </blockquote> <p>Since you chose to bind manually to a DataSet, you need to do the "magic" yourself; in other words, you handle the OnSort command, get the sort expression, get your data source again (however you do it, from Session or by calling the database again) and do your sort similarly to the lines shown above and rebind to your Gridview.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload