I have a list of items stored in a database.
I am using a foreach to list the items returned with a checkbox next to each item like so:
var db = Database.Open(database);
var sql = SELECT * from table;
var result = db.Query(sql);
...
@{foreach (var user in result) {
<tr><td>@table.attribute</td> <td>@table.secondAttribute @table.thirdAttribute</td>
<td><input type=checkbox name=attribute value=attribute /></td></tr>
The functionality I would like to have is a textbox which, upon the user typing a letter, would limit the number of items listed by my foreach based on what character the user enters. So I've tried to use the JQuery autoComplete module, but I'm not entirely sure how to use it in this case, or even if it is possible.
So I added in :
$(function(){
$('#name').autocomplete({source:'getUsers'});
});
...
Enter their name:
And then in getUsers :
@{
var db = Database.Open(database);
var term = Request.QueryString[term] + %;
var sql = SELECT * from table where attribute LIKE @0 OR secondAttribute LIKE @0 OR thirdAttribute LIKE @0;
var result = db.Query(sql, term);
var data = result.Select(p => new{label = p.attribute + + p.secondAttribute});
Json.Write(data, Response.Output);
}
This, of course, just retrieves the data for the textbox and doesn't delimit the returned checkboxes at all. Is there a way I can do this ?