Created
May 14, 2017 08:29
-
-
Save kaushalparik27/92f54cc626802f8814755b4a8fe2d937 to your computer and use it in GitHub Desktop.
Bootstrap AutoComplete - Basic Configuration - 02
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class WebForm68 : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
} | |
//-- actual webmethod that will fetch data from database based on what user typed | |
[WebMethod] | |
public static string[] GetEmployeeData(string SearchParam) | |
{ | |
List<string> empList = new List<string>(); | |
using (SqlConnection conn = new SqlConnection()) | |
{ | |
conn.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; | |
using (SqlCommand cmd = new SqlCommand()) | |
{ | |
cmd.CommandText = "select EmpName, EmpId from EmployeeTable where EmpName like @SearchParam + '%'"; | |
cmd.Parameters.AddWithValue("@SearchParam", SearchParam); | |
cmd.Connection = conn; | |
conn.Open(); | |
using (SqlDataReader sdr = cmd.ExecuteReader()) | |
{ | |
while (sdr.Read()) | |
empList.Add(string.Format("{0}-{1}", sdr["EmpName"], sdr["EmpId"])); | |
} | |
conn.Close(); | |
} | |
} | |
return empList.ToArray(); | |
} | |
//-- generate sample data for auto complete just to demonstrate | |
[WebMethod] | |
public static string[] GetEmployeeDataSample(string SearchParam) | |
{ | |
List<string> empList = new List<string>(); | |
for (int i = 0; i < 10; i++) | |
{ | |
string data = (i + 1).ToString(); | |
data += "-EmpName " + (i + 1).ToString(); | |
empList.Add(data); | |
} | |
return empList.Where(x => x.ToLower().Contains(SearchParam)).ToArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment