title: Parsing Dynamic SQL in C# and binding to WebGrid in ASP.Net MVC
body: <p>Parsing Dynamic SQL in C# and binding to WebGrid in ASP.Net MVC
  I have dynamic SQL Queries that uses pivot to produce result and the resultset may be like this.:</p>
  
  <pre><code>Name    Div1    Div2    Div3    Div4    Div5
  Active  1   0   0   0   0
  Busy    0   0   0   0   1
  NA  0   1   0   0   0
  Suspended   0   0   0   1   0
  </code></pre>
  
  <p>There can be n number of divisions. I want to bind this data with ASP.NET MVC WebGrid control. I am not able to achieve this.</p>
  
  <p>My C# code is given below:</p>
  
  <pre><code>dynamic list = db.ExecuteStoreQuery&lt;dynamic&gt;("exec [dbo].[proc_GetData]").ToList();
  return list;
  </code></pre>
  
  <p>I want to bind this list with ASP.NET MVC Webgrid, my webgrid code as below:</p>
  
  <pre><code>WebGrid grid = new WebGrid(Model.DataList);
  
  List&lt;WebGridColumn&gt; list = new List&lt;WebGridColumn&gt;();
  
  list.Add(new WebGridColumn
  {
      Header = "Name",
      ColumnName = "Name"
  });
  
  foreach (var item in Model.DivList)
  {
    list.Add(new WebGridColumn
    {
      Header = item,
      ColumnName = item
    });
  }
  
  @grid.GetHtml(tableStyle: "webgrid",
  alternatingRowStyle: "webgrid-alternating-row",
  headerStyle: "webgrid-header",
  footerStyle: "webgrid-footer",
  selectedRowStyle: "webgrid-selected-row",
  rowStyle: "webgrid-row-style",
  columns: col);
  </code></pre>
  
  <p>This one is not working. Please help me how can I achieve this task.
  Thanks.</p>