Click here to Skip to main content
11,492,974 members (55,685 online)
Rate this: bad
good
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
Edited 29-Nov-12 2:21am
(no name)43.4K
v2
Comments
Krunal R at 29-Nov-12 6:06am
   
You are here passing only username but what about fetching data ?? have you done that ??
azizulhoque.bd at 29-Nov-12 6:14am
   
Hi.., Please explain with code.
sarath.mk at 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 at 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 at 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
0 Sergey Alexandrovich Kryukov 419
1 Maciej Los 286
2 F-ES Sitecore 224
3 KarstenK 210
4 CPallini 208
0 Sergey Alexandrovich Kryukov 10,062
1 OriginalGriff 8,620
2 Sascha Lefèvre 3,609
3 Maciej Los 3,372
4 Richard Deeming 2,500


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 29 Nov 2012
Copyright © CodeProject, 1999-2015
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