How to use filter for a combobox in C # .NET using SQL Server?

0

I need to give an improvement on a project that I'm doing in MVC, with SQL and I already did a combobox that takes the data from the database, but I need to create a page to filter data from the database.

Ex: I have a text field and a combobox with database data types, I do not want just one data, for example if I want to only filter by a type, or by name. How can I do this without doing multiple combobox?

    
asked by anonymous 16.07.2015 / 14:57

1 answer

0

Hello. From what I understand, you can use jQuery to add new "filter lines" in your form (using the append function, for example) and submit that data as string arrays for your action. In the action you go through the arrays with column names and values (maybe also type, such as CONTAINS, DOES NOT CONTAIN, etc.) and generates your query.

To generate new rows, there are a few ways:

  • Create a new div; create the inner elements and insert them into the div; insert the div into the form.
  • Add the div already with the inner elements by inserting direct HTML code ( $("#meuform").append("<div><select...") ).
  • Create an action that returns a view with only one filter line, containing the select, input, button, and so on. Make a load and load this view via Ajax by inserting it into form.
  • Create a "template" div containing the elements of the filter (select, input, etc), leave it with display: none and to insert a new line in the form, copy the contents of that div (using the html (), for example).

With these lines created in the form, you submit to your action and there it generates the query.

    
21.07.2015 / 15:33