i have a users list that i would like to be able to get all logged in users by search on autocomplete
how can i do that?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Roei BarRank #1,271 · 1.4K reputationPosted Aug 17, 2009, 6:55 AM EDT
its using Json over RPC
you basically need to create a handler file
like this
using System; using System.Web; using Jayrock.Json; using Jayrock.JsonRpc; using Jayrock.JsonRpc.Web; public class Lookup : JsonRpcHandler { public Collection Lookup(string q) { Collection Users = new Collection(); RequestClass myRequest = new RequestClass(); UserEmployee User = new UserEmployee(); DataRow dr = default(DataRow); DataTable dt = default(DataTable); dt = myRequest.GetUser(q); foreach (var dr in dt.Rows) { User.FullName = dr("FullName"); User.UserID = dr("UserID"); User.Job = dr("Job"); Users.Add(new UserEmployee(User)); } dt.Dispose(); return Users; } } public class UserEmployee { public string FullName; public string UserID; public string Job; public UserEmployee() { } public UserEmployee(UserEmployee User) { this.FullName = User.FullName; this.UserID = User.UserID; this.Job = User.Job; } }and a simple form
on the head put the following
.suggestionsBox { position: relative; left: 30px; margin: 10px 0px 0px 0px; width: 200px; background-color: #212427; -moz-border-radius: 7px; -webkit-border-radius: 7px; border: 2px solid #000; color: #fff; } .suggestionList { margin: 0px; padding: 0px; } .suggestionList li { margin: 0px 0px 3px 0px; padding: 3px; cursor: pointer; } .suggestionList li:hover { background-color: #659CD8; } function jQueryChannel() { this.rpc = function(call) { if (!call.callback) throw new Error('Synchronous calls not supported.'); $.ajax({ type: "POST", url: call.url, data: JSON.stringify(call.request), beforeSend: function(xhr) { xhr.setRequestHeader("X-JSON-RPC", call.request.method); }, success: function(s) { call.callback(JSON.eval(s)); } }); } } function suggest(inputString) { if(inputString.length > 3) { var lookup = new Lookup(); //Instantiates new Jayrock Proxy from *.ashx?proxy lookup.channel = new jQueryChannel(); // Overrides default Jayrock Proxy Channel lookup.Lookup(inputString, function(data) { //$('#test').html("Length: " + data.result.length + " Test" + dump(data.result)); var results = data.result; if (results.length > 0) { var html = ""; //html += ""; for(var i = 0; i " + results[i].fullName + " (" + results[i].job + ") " + " " + results[i].userID + " "; } //html += ""; $('#autoSuggestionsList').html(html); $('#suggestions').show(); } }); } else { // Hide the suggestion box. $('#suggestions').hide(); } } // lookup function fill(value) { $("#ctl00_ContentPlaceHolder1_txtUserID").val(value); setTimeout("$('#suggestions').hide();", 200); }on the body
and In your code behind (*.aspx.cs) add to the Page_Load function:
thats it :-)
Kirtan PatelRank #292 · 8.6K reputationPosted Aug 17, 2009, 8:53 AM EDT
Windows Form or ASp.net ?