using System; |
using System.Data; |
using System.Configuration; |
using System.Web; |
using System.Web.Security; |
using System.Web.UI; |
using System.Web.UI.WebControls; |
using System.Web.UI.WebControls.WebParts; |
using System.Web.UI.HtmlControls; |
using System.Data.SqlClient; |
using Telerik.WebControls; |
using System.Text.RegularExpressions; |
|
public partial class _Default : System.Web.UI.Page |
{ |
|
protected void Page_Load(object sender, EventArgs e) |
{ |
|
} |
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
{ |
string connectionstring = "Data Source=(local); Initial Catalog=NorthWind;User ID=sa; Password=sa"; |
SqlConnection conn = new SqlConnection(connectionstring); |
conn.Open(); |
SqlDataAdapter adp = new SqlDataAdapter("select * from Products", conn); |
DataTable dtCurrentData = new DataTable(); |
adp.Fill(dtCurrentData); |
RadGrid1.DataSource = dtCurrentData; |
conn.Close(); |
|
} |
protected void RadGrid1_PreRender(object sender, EventArgs e) |
{ |
foreach (GridDataItem item in RadGrid1.MasterTableView.Items) |
{ |
foreach (GridColumn col in RadGrid1.MasterTableView.Columns) |
{ |
item[col.UniqueName].Text = Highlight(TextBox1.Text, item[col.UniqueName].Text); |
} |
} |
|
} |
protected void Button1_Click(object sender, EventArgs e) |
{ |
RadGrid1.Rebind(); |
} |
|
public string Highlight(string Search_Str, string InputTxt) |
{ |
|
// Setup the regular expression and add the Or operator. |
Regex RegExp = new Regex(Search_Str.Replace(" ", "|").Trim(), RegexOptions.IgnoreCase); |
// Highlight keywords by calling the delegate each time a keyword is found. |
return RegExp.Replace(InputTxt, new MatchEvaluator(ReplaceKeyWords)); |
// Set the RegExp to null. |
|
} |
|
public string ReplaceKeyWords(Match m) |
{ |
|
return "<span class=highlight>" + m.Value + "</span>"; |
|
} |
} |
|