📄 defaultcs.aspx.cs
字号:
using System;
using System.Data;
using System.IO;
using Telerik.QuickStart;
using Telerik.WebControls;
namespace Telerik.ComboboxExamplesCS.ClientEvents
{
/// <summary>
/// Summary description for _Default.
/// </summary>
public class DefaultCS: XhtmlPage
{
protected RadComboBox RadComboBox1;
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 tempWord = word.Trim().Split(':')[0];
words.Rows.Add(new string [] { tempWord });
word = sr.ReadLine();
}
sr.Close();
Cache["dictionaryWords"] = words;
}
dictionaryWords = (DataTable) Cache["dictionaryWords"];
}
private void RadComboBox1_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
{
LoadData();
RadComboBox1.Items.Clear();
string text = e.Text;
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()));
}
e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), rows.Length.ToString());
}
private void Page_Load(object sender, 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 RadComboBoxItemsRequestedEventHandler(this.RadComboBox1_ItemsRequested);
this.Load += new EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -