page:
<style type="text/css"> .highlight { background: yellow; color: red; } </style> <asp:Label ID="searchTextlab" runat="server" Style="color: #ffffff; font-size: 1px;"></asp:Label> <script type="text/javascript"> $(function () { var searchText = document.getElementById(‘<%=gridYearBidDetailed.ClientID %>‘); var searchTexta = document.getElementById(‘<%=searchTextlab.ClientID %>‘).innerHTML; if (searchTexta.length == 0) { console.log("没有关键词"); return false; } var regExp = new RegExp(searchTexta, ‘g‘); searchText.innerHTML = searchText.innerHTML.replace(regExp, ‘<span class="highlight">‘ + searchTexta + ‘</span>‘); flag = 1; if (flag) { var arr = Object.keys($(".highlight")); if (arr.length > 1) { var _top = $(".highlight").eq(0).offset().top; $("html,body").animate({ "scrollTop": _top }) } } }); </script>
controller:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Sessioninfo(); } } private void Sessioninfo() { if (Session["searchText"] != null) searchTextlab.Text = Session["searchText"].ToString(); } protected void gridYearBidDetailed_RowCommand(object sender, GridViewCommandEventArgs e) { switch (e.CommandName) { case "info": searchTextlab.Text = ""; Session.Add("searchText", BiddingNo); Response.Redirect(EditUrl("a", a, "page")); break; } protected void bnck_click(object sender, EventArgs e) { searchTextlab.Text = ""; Session.Remove("searchText"); FillUI(); } --