📄 defaultcs.aspx.cs
字号:
using System;
using Telerik.QuickStart;
using Telerik.WebControls;
using System.Data;
using System.Data.OleDb;
namespace Telerik.ComboboxExamplesCS.AutoCompleteSql
{
/// <summary>
/// Summary description for _Default.
/// </summary>
public class DefaultCS: XhtmlPage
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.CheckBox CheckBox1;
protected System.Web.UI.WebControls.CheckBox Checkbox2;
protected Telerik.WebControls.RadComboBox RadComboBox1;
private void RadComboBox1_ItemsRequested(object o, Telerik.WebControls.RadComboBoxItemsRequestedEventArgs e)
{
RadComboBox combo = (RadComboBox) o;
combo.Items.Clear();
string mdbPath = Server.MapPath("~/Combobox/Data/NWind.mdb");
OleDbConnection dbCon = new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + mdbPath);
dbCon.Open();
string text = e.Text;
string sql = "SELECT * from Customers WHERE CompanyName LIKE '" + text.Replace("'","''") + "%'";
OleDbDataAdapter adapter = new OleDbDataAdapter(sql, dbCon);
DataTable dt = new DataTable();
adapter.Fill(dt);
dbCon.Close();
foreach (DataRow row in dt.Rows)
{
RadComboBoxItem item = new RadComboBoxItem(row["CompanyName"].ToString().ToLower());
item.Value = row["CompanyName"].ToString();
combo.Items.Add(item);
}
}
private void Page_Load(object sender, System.EventArgs e)
{
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.RadComboBox1.ItemsRequested += new Telerik.WebControls.RadComboBoxItemsRequestedEventHandler(this.RadComboBox1_ItemsRequested);
this.CheckBox1.CheckedChanged += new System.EventHandler(this.CheckBox1_CheckedChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
if (RadComboBox1.Text != String.Empty)
{
Label1.Text = "You selected text: <b>" + RadComboBox1.Text + "</b> and value : <b>" + RadComboBox1.Value + "</b>";
}
else
{
Label1.Text = "ComboBox is empty";
}
}
private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
RadComboBox1.MarkFirstMatch = CheckBox1.Checked;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -