Click here to Skip to main content
15,893,337 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Freinds,

I have Autocomplete Textbox to which i am binding user name. After selecting the correct user name from autocomplete textbox, i need to pass the corresponding user id to fetch the user information. But I am able to pass only user name. Please suggest me with the above requirement.

Thanking you....

 Entity dynentity2 = collection.Entities[i];
                                if (dynentity2.Attributes.Count > 0 && dynentity2.Attributes.Contains("systemuserid"))
                                {
                                    
                                        string strUserId = string.Empty;
                                        string strUserName = string.Empty;
                                        if (dynentity2.Attributes.Contains("systemuserid"))
                                            strUserId = Convert.ToString((dynentity2.Attributes["systemuserid"]));

                                        if (dynentity2.Attributes.Contains("fullname"))
                                            strUserName = Convert.ToString((dynentity2.Attributes["fullname"]));
                                        
                                        UserItem objItem = new UserItem();
                                        objItem.UserId = strUserId;
                                        objItem.UserName = strUserName;
                                        lstUsers.Add(objItem);
                                     }

Autocomplete textbox web method by typing username, returns List collection:
 [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]   
        public static List GetCompletionList(string prefixText, int count, string contextKey) {
            List objReturnList = new List();
            try
            {
                var products = lstUsers.Select(p => p.UserName.ToLower().StartsWith(prefixText.ToLower())).ToList();
                foreach (UserItem objItem in lstUsers)
                {
                    if (objItem.UserName.ToLower().StartsWith(prefixText.ToLower()))
                    {
                        objReturnList.Add(objItem.UserName);
                    }
                }
                return objReturnList.Distinct().ToList();

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally {
                objReturnList = null;
            }
    }
Posted
Updated 29-Nov-12 1:21am
v2
Comments
[no name] 29-Nov-12 6:06am    
You are here passing only username but what about fetching data ?? have you done that ??
azizulhoque.bd 29-Nov-12 6:14am    
Hi.., Please explain with code.
sarath.mk 29-Nov-12 6:25am    
Here is my code,
UserId and UserName is retrieved and binding to List<useritem> collection:
Entity dynentity2 = collection.Entities[i];
if (dynentity2.Attributes.Count > 0 && dynentity2.Attributes.Contains("systemuserid"))
{

string strUserId = string.Empty;
string strUserName = string.Empty;
if (dynentity2.Attributes.Contains("systemuserid"))
strUserId = Convert.ToString((dynentity2.Attributes["systemuserid"]));

if (dynentity2.Attributes.Contains("fullname"))
strUserName = Convert.ToString((dynentity2.Attributes["fullname"]));

UserItem objItem = new UserItem();
objItem.UserId = strUserId;
objItem.UserName = strUserName;
lstUsers.Add(objItem);
}

Autocomplete textbox web method by typing username, returns List<string> collection:
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static List<string> GetCompletionList(string prefixText, int count, string contextKey) {
List<string> objReturnList = new List<string>();
try
{
var products = lstUsers.Select(p => p.UserName.ToLower().StartsWith(prefixText.ToLower())).ToList();
foreach (UserItem objItem in lstUsers)
{
if (objItem.UserName.ToLower().StartsWith(prefixText.ToLower()))
{
objReturnList.Add(objItem.UserName);
}
}
return objReturnList.Distinct().ToList();

}
catch (Exception ex)
{
throw ex;
}
finally {
objReturnList = null;
}
}
sarath.mk 29-Nov-12 6:26am    
when user selects the correct user, i have to pass the Userid(not UserName) to my DB to fetch his information.
ZurdoDev 29-Nov-12 8:38am    
You'll have to somehow also retrieve the userid and store it in a hidden field or something.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900