Click here to Skip to main content
14,977,980 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have to create auto text completion textbox in asp.net

I have tried this method that without using webservices


This is my method

C#
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public static string[] GetProductList(string prefixText, int count)
{
    // Get the Products From Data Source. Change this method to use Database
    List<string> empList = GetEmpNames();

    // Find All Matching Products
    var list = from p in empList
               where p.Contains(prefixText)
               select p;

    //Convert to Array as We need to return Array
    string[] prefixTextArray = list.ToArray<string>();

    //Return Selected Products
    return prefixTextArray;
}

private  List<string> GetEmpNames()
{

    Entities objEntity=new Entities();
    var empList = (from empDetails in objEntity.HCM_EMPLOYEE_DETAILS
                   select empDetails).ToList();
    return empList;

}




colud you please tell me how to return var data to list method my intention is below method i will call to above method.

so please help me..
Posted
v2
Comments
DGKumar 15-Jan-14 1:53am
   
Hi i have changed the below method as static but the error will display as
"An object reference is required for non static method or property" at objEntity
var empList = (from empDetails in objEntity.HCM_EMPLOYEE_DETAILS
select empDetails).ToList();

make the method as static.
C#
private static List<string> GetEmpNames()
   
v2
When you do the Linq to Objects query, it will return you the type IEnumerable<Student>, you can use the ToList()[^] method to create a List<T> from an IEnumerable<T>:

XML
var selected = from s in studentCollection
                           select s;

List<Student> selectedCollection = selected.ToList();

This may help.
   
v2

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