Question

I'm working with asp. Net mvc3 and i'm using sql server 2008 as backend.I have to display a table in front end that will have a dynamic columns is it possible in c# for example 1st time when I execute stored procedure it'll return 4 columns with values and next time it'll return 5 columns with values I shouldnot make any code changes when one more column added to the table in backend is it possible in asp .net mvc3? Is anyone of u faced such a scenario?

Was it helpful?

Solution

First, I think it might be easier if you would use an ORM like Entity Framework, instead of ADO.NET.

For the frontend I would recommend Grid.MVC. Here's an simple example to get you started http://www.codeproject.com/Tips/597253/Using-the-Grid-MVC-in-ASP-NET-MVC

For the frontend you could use an if in the cshtml file such as:

@{
    if(Model.Property != null) //Receives 4 columns, 1 Property is initialized with NULL
    {
         //Render grid with 4 columns
    }
    else  // Receives 5 columns, all properties !=null
    {
         //Render grid with 5 columns
    }
}

If you feel more comfortable with javascript, you can use jqgrid.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top