title: DataTable group by and iterate through C#
body: <p>I have a datatable which was returned from database.</p>
  
  <p>the content is similar below:</p>
  
  <pre><code>UserId | Address | Phone
   1        blah     0123
   1        blah2    3445
   2        sdsdf    2343
   2        ssf      2223
   3        sadss    2321
  </code></pre>
  
  <p>This is the content of DataTable which is returned from database.</p>
  
  <p>Now I just would like to group  the results by User Id and loop through to out put result</p>
  
  <p>foreach (DataRow userRow in DataTableGroupedByUser){</p>
  
  <p>foreach (DataRow restOfColumns in AddressAndPhoneRows){</p>
  
  <p>Output user details
  }
  }</p>
  
  <p>The output I would get should be:</p>
  
  <pre><code>User Id: 1
  
  Address   Phone
  1- blah   0123
  2- blah2  3445
  
  User Id 2:
    Address   Phone
  1- sdsdf    2343
  2- ssf      2223
  </code></pre>
  
  <p>user Id :3 
   ...</p>
  
  <p>I hope you get the idea.</p>
  
  <p>Basically I do not want to query the database many times for each user but just use one query to pull all data and handle the grouping in the memory.</p>
  
  <p>There are also other reason for this. </p>
  
  <p>Is there any way to achieve this by using DataTable and filtering?</p>