Search code examples
model-view-controllerwebgrid

how to sort select DropDownList items in mvc 4 webgrid?


I'm working on mvc$ webgrid viewer, my grid viewer lists all columns exactlly as I want but there is one problem when I sort grid content by clicking on the hyperlink of the column names it sorts for all the columns except the drop down menu or DropDownList in mvc viwer. [![mvc4 webgrid view screenshoot][1]][1]

DropDownList is not sorted as the other column values.

Solution

  • call a function that have the set of selectlist items. for example, in my case it works when I make the webgrid as follows:

    grid.Column(columnName: "ContractFileNamesList", header: "ContractFileNamesList", format: @item => Html.DropDownList("filename",
     , "-- Select One --"))
    

    especially,

    (IEnumerable)Model.ContractBOModel[rowVal - 1].FileNameListsFunction(fileNameStr);