Hi,
We will learn how to enable AutoCompleteExtender in Textbox Control.
Here, We will learn to Map data from SQL Database to Textbox within Same Page. WebMethod in .cs Page.
Now Code in ASPX.CS Page
Add these Namespages for below Code.
We will learn how to enable AutoCompleteExtender in Textbox Control.
Here, We will learn to Map data from SQL Database to Textbox within Same Page. WebMethod in .cs Page.
Directly to Code:
ASPX Page CodeVehicle No : |
Now Code in ASPX.CS Page
Add these Namespages for below Code.
using System.Data; // For Dataset
using System.Data.SqlClient; // For SQlConnection/Adaptor
using System.Configuration; // Access Consting from Web.Config.
using System.Collections.Generic;
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]I have Selected Only Unique Value from Database using SELECT DISTINCT .... command. If you want all records, Simply Change SQL Query to SELECT ..... Will be glad to hear from you... This Post is copied from DotNetFunda where I wrote in Code section.
public static string[] GetVehicleList(string prefixText, int count, string contextKey)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConToJohn"].ConnectionString);
SqlDataAdapter adp = new SqlDataAdapter("Select distinct VehicleNo from VehicleDispatch where VehicleNo like '%" + prefixText + "%'", con);
DataSet ds = new DataSet();
adp.Fill(ds, "Vehicles");
string[] VehicleNo = new string[ds.Tables["Vehicles"].Rows.Count];
for (int i = 0; i <= ds.Tables["Vehicles"].Rows.Count - 1; i++)
{
VehicleNo.SetValue(ds.Tables["Vehicles"].Rows[0][0].ToString(), i);
}
return VehicleNo;
}
0 comments:
Post a Comment
Leave your Feedback or Suggestion. We will be Happy to read and reply.