Hi suhaas121,
Refer below example.
HTML
Test
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<p>This is main content.</p>
<p>File is the type of jpg</p>
<p>Remove the row.</p>
<p>The file is ok</p>
<p>Install in progress</p>
<p>Main memu added.</p>
</body>
</html>
Default
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
PageSize="4" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" BackColor="White"
BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" Width="100%">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="UserId" HeaderText="UserId" SortExpression="UserId" />
<asp:BoundField DataField="BookmarkLineText" HeaderText="BookmarkLineText" SortExpression="BookmarkLineText" />
<asp:BoundField DataField="iNodeId" HeaderText="iNodeId" SortExpression="iNodeId" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
Home
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var searchWord = $("#hfWord").val();
var iframeHtml = $("#hfHTML").val();
iframeHtml = iframeHtml.replace(new RegExp(searchWord, "gi"), function (match) {
return '<span style="background-color: yellow;">' + match + '</span>'
});
$('#frmDisplay').contents().find('body').html(iframeHtml);
if ($('#frmDisplay').contents().find('#lblHighlight').length > 0) {
$('#frmDisplay').contents().find('#lblHighlight')[0].scrollIntoView()
}
});
</script>
<asp:HiddenField ID="hfWord" runat="server" />
<asp:HiddenField ID="hfHTML" runat="server" />
<iframe id="frmDisplay" runat="server" frameborder="0" height="500"></iframe>
Code
Default
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[3] {
new System.Data.DataColumn("UserId", typeof(string)),
new System.Data.DataColumn("BookmarkLineText", typeof(string)),
new System.Data.DataColumn("iNodeId",typeof(int)) });
dt.Rows.Add("Admin", "Remove", 5);
dt.Rows.Add("Admin", "Install", 3);
dt.Rows.Add("Admin", "main", 27);
dt.Rows.Add("Admin", "the", 23);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["search"] = GridView1.SelectedRow.Cells[1].Text;
Session["text"] = GridView1.SelectedRow.Cells[2].Text;
Response.Redirect("Home.aspx");
}
Home
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
if (Session["search"] != null)
{
hfWord.Value = Session["text"].ToString();
getbookmark();
}
}
}
public void getbookmark()
{
// Read the html and set in HiddenField.
hfHTML.Value = System.IO.File.ReadAllText(Server.MapPath("~/Test.html"));
}
Screenshot