Click here to Skip to main content
12,068,967 members (71,340 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 29-Nov-12 1:02am
sarath.mk1.1K
Edited 29-Nov-12 2:21am
v2
Comments
Krunal R 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 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 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;
}
}
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.
ryanb31 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100