title: take top 10 or 20 rows from dynamic datatable
body: <p>I have 100 records in my Datable says to be in</p>
  
  <pre><code>DataTable dt=new DataTable();
  </code></pre>
  
  <p><code>dt</code> have <code>100</code> of records say column name as <code>sub_id(contain int datatype)</code> and <code>subheadername(contain nvarchar(150))</code> , I want top <code>20 records</code> from this <code>dt</code> in <code>ascending</code> order</p>
  
  <p>I am putting code as </p>
  
  <pre><code>//dtlcategories.DataSource = dt.AsEnumerable().OrderBy(x =&gt; x["subheadername"]).Take(20).ToList();
  dtlcategories.DataSource = dt.Rows.Cast&lt;DataRow&gt;().OrderBy(x =&gt; x["subheadername"]).Take(20).ToList();
  dtlcategories.DataBind();
  </code></pre>
  
  <p>Here dtlcategories is Datalist but on running error is coming as 'System.Data.DataRow' does not contain a property with the name 'subheadername'.</p>
  
  <p><strong>ANSWER IS SOLVED</strong></p>
  
  <pre><code>dtlcategories.DataSource = dt.Rows.Cast&lt;DataRow&gt;().OrderBy(x =&gt; x["subheadername"]).Take(20).copytodatatable();
  dtlcategories.DataBind();
  </code></pre>