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.:
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
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.
My C# code is given below:
dynamic list = db.ExecuteStoreQuery<dynamic>("exec [dbo].[proc_GetData]").ToList();
return list;
I want to bind this list with ASP.NET MVC Webgrid, my webgrid code as below:
WebGrid grid = new WebGrid(Model.DataList);
List<WebGridColumn> list = new List<WebGridColumn>();
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);
This one is not working. Please help me how can I achieve this task. Thanks.