📄 defaultcs.aspx.cs
字号:
using System;
using System.IO;
using Telerik.QuickStart;
using Telerik.WebControls;
using System.Data;
using System.Data.OleDb;
namespace Telerik.ComboboxExamplesCS.AutoCompleteDictionary
{
/// <summary>
/// Summary description for _Default.
/// </summary>
public class DefaultCS: XhtmlPage
{
protected Telerik.WebControls.RadComboBox RadComboBox1;
protected System.Web.UI.WebControls.CheckBox CheckBox1;
protected System.Web.UI.WebControls.CheckBox Checkbox2;
DataTable dictionaryWords = new DataTable();
private void LoadData()
{
string tdfPath = Server.MapPath("~/Combobox/Data/en-US.tdf");
if (Cache["dictionaryWords"] == null)
{
DataTable words = new DataTable("words");
DataColumn column = words.Columns.Add("word");
string word = String.Empty;
StreamReader sr = File.OpenText(tdfPath);
word = sr.ReadLine();
while (word != null)
{
string realWord = word.Split(':')[0];
words.Rows.Add(new string [] { realWord });
word = sr.ReadLine();
}
sr.Close();
Cache["dictionaryWords"] = words;
}
dictionaryWords = (DataTable) Cache["dictionaryWords"];
}
private void RadComboBox1_ItemsRequested(object o, Telerik.WebControls.RadComboBoxItemsRequestedEventArgs e)
{
LoadData();
RadComboBox1.Items.Clear();
string text = e.Text;
try
{
DataRow [] rows = dictionaryWords.Select("word LIKE '" + text + "*'");
int itemsPerRequest = 20;
int itemOffset = e.NumberOfItems;
int endOffset = itemOffset + itemsPerRequest;
if (endOffset > rows.Length)
{
endOffset = rows.Length;
}
for (int i=itemOffset; i<endOffset; i++)
{
RadComboBox1.Items.Add(new RadComboBoxItem(rows[i]["word"].ToString(),rows[i]["word"].ToString()));
}
if (rows.Length > 0)
{
e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), rows.Length.ToString());
}
else
{
e.Message = "No matches";
}
}
catch (Exception ex)
{
e.Message = "No matches";
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
LoadData();
}
}
#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.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
RadComboBox1.Text = String.Empty;
RadComboBox1.MarkFirstMatch = CheckBox1.Checked;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -