C# ASPxComboBox6模糊查询解决方案
C# ASPxComboBox6模糊查询
protected void ASPxComboBox6_TextChanged(object sender, EventArgs e)
{
string NumDrop = this.ASPxComboBox6.Text.Trim();
string carnum_query = "SELECT car_num, car_type, driver, tel, id FROM dbo.diaodu_car_base WHERE car_num LIKE '%" + NumDrop + "%'";
Response.Write(carnum_query);
string strConnnection = System.Configuration.ConfigurationManager.ConnectionStrings["emailConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnnection);
//创建OleDbDataAdapter对象,按照指定的查询语句获取结果
SqlDataAdapter cmd = new SqlDataAdapter(carnum_query, con);
//定义DataSet对象,将查询结果填充到这个对象上
DataSet ds = new DataSet();
cmd.Fill(ds, "contents");
//绑定数据源
this.ASPxComboBox6.DataSourceID = null;
this.ASPxComboBox6.ID = "";
this.ASPxComboBox6.DataSource = ds.Tables["contents"].DefaultView;
this.ASPxComboBox6.ID = "id";
this.ASPxComboBox6.DataBind();
if (con.State == ConnectionState.Closed)
{
con.Open();
}
List<string> car_num = new List<string>();
foreach (DataRow row in ds.Tables[0].Rows)
{
foreach (DataColumn column in ds.Tables[0].Columns)
{
car_num.Add(row[column].ToString());
}
}
int index=0;
for (int i = 0; i < car_num.Count; i++)
{
if (car_num[i] == NumDrop)
{
index = i;
}
}
this.ASPxComboBox6.DataSource = ds ;
this.ASPxComboBox6.SelectedIndex = index ;
}
运行提示错误:The DataSourceID property of 'ASPxComboBox6' must refer to an existing control. There is no control with the specified ID: '(无)'. 哪里的问题?
protected void ASPxComboBox6_TextChanged(object sender, EventArgs e)
{
string NumDrop = this.ASPxComboBox6.Text.Trim();
string carnum_query = "SELECT car_num, car_type, driver, tel, id FROM dbo.diaodu_car_base WHERE car_num LIKE '%" + NumDrop + "%'";
Response.Write(carnum_query);
string strConnnection = System.Configuration.ConfigurationManager.ConnectionStrings["emailConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnnection);
//创建OleDbDataAdapter对象,按照指定的查询语句获取结果
SqlDataAdapter cmd = new SqlDataAdapter(carnum_query, con);
//定义DataSet对象,将查询结果填充到这个对象上
DataSet ds = new DataSet();
cmd.Fill(ds, "contents");
//绑定数据源
this.ASPxComboBox6.DataSourceID = null;
this.ASPxComboBox6.ID = "";
this.ASPxComboBox6.DataSource = ds.Tables["contents"].DefaultView;
this.ASPxComboBox6.ID = "id";
this.ASPxComboBox6.DataBind();
if (con.State == ConnectionState.Closed)
{
con.Open();
}
List<string> car_num = new List<string>();
foreach (DataRow row in ds.Tables[0].Rows)
{
foreach (DataColumn column in ds.Tables[0].Columns)
{
car_num.Add(row[column].ToString());
}
}
int index=0;
for (int i = 0; i < car_num.Count; i++)
{
if (car_num[i] == NumDrop)
{
index = i;
}
}
this.ASPxComboBox6.DataSource = ds ;
this.ASPxComboBox6.SelectedIndex = index ;
}
运行提示错误:The DataSourceID property of 'ASPxComboBox6' must refer to an existing control. There is no control with the specified ID: '(无)'. 哪里的问题?