refer this
<form id="form1" runat="server">
<asp:TextBox ID="RefNo" runat="server"></asp:TextBox>
<asp:Button ID="btn" runat="server" Text="search" OnClick="btn_Click"/>
<asp:GridView ID="Search" runat="server" CssClass="table table-bordered table-hover" AutoGenerateColumns="False" OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField DataField="ID" Visible="False" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Address" HeaderText="Address" />
</Columns>
</asp:GridView>
</form>
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}
public void BindData() {
DataTable dt = new DataTable();
dt.Columns.Add("ID");
dt.Columns.Add("Name");
dt.Columns.Add("Address");
dt.Rows.Add(1, "karthik", "Bangalore india");
dt.Rows.Add(2, "prasanth", "Tamilnadu india");
dt.Rows.Add(2, "sachin", "Mumbai india");
dt.Rows.Add(2, "sehwag ", "delhi india");
Search.DataSource = dt;
Search.DataBind();
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string seachtext = RefNo.Text.Trim();
int[] colsToCheck = new int[] {0,1,2};
for (int i = 0; i < colsToCheck.Length; i++)
{
int colIndex = colsToCheck[i];
e.Row.Cells[colIndex].Text = Regex.Replace(e.Row.Cells[colIndex].Text, seachtext, delegate(Match match)
{
return string.Format("<span style = 'background-color:yellow'>{0}</span>", match.Value);
}, RegexOptions.IgnoreCase);
}
}
}
protected void btn_Click(object sender, EventArgs e)
{
BindData();
}