0

In MVC4 application I can able to bind the database table columns into the Grid Header. But I need to bind the database table columns values as a Grid header. Is this possible in MVC?

Example:

tbl_staticfield table have the fieldname Column this column have some values,that values need to bind the Grid header and then the corresponding field name have some values these values are stored tbl_customfielddetails these also bind under the corresponding Grid header.

4
  • 1
    IF a table has more than one record then how many headers you'll have? Please elaborate your problem. Commented Jul 31, 2014 at 10:44
  • Yes I have 18 columns now as a header.But it is possible to increment in the future..
    – ilaya
    Commented Jul 31, 2014 at 11:34
  • Ok, which grid control you're using for this now? Commented Jul 31, 2014 at 13:13
  • Problem is not related with MVC but the logics. Commented Aug 1, 2014 at 9:14

1 Answer 1

0

When you create the webgrid object, first argument is source(rows), second is column names(List of columns). In your case, it would be dynamic. So it would be like

var Columns = context.tbl_staticfield.select(m => m.fieldname).toList();
var grid = new WebGrid(Model, Columns, ....);

I assume context is your database context.

Ref: http://msdn.microsoft.com/en-us/library/system.web.helpers.webgrid.webgrid(v=vs.111).aspx

public WebGrid(
    IEnumerable<Object> source,
    IEnumerable<string> columnNames,
    string defaultSort,
    int rowsPerPage,
    bool canPage,
    bool canSort,
    string ajaxUpdateContainerId,
    string ajaxUpdateCallback,
    string fieldNamePrefix,
    string pageFieldName,
    string selectionFieldName,
    string sortFieldName,
    string sortDirectionFieldName
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.