单击表中的链接时突出​​显示HTML表

时间:2022-07-12 01:26:49

I have a lengthy asp.net page. A HTML table in the page has a link. when the link is clicked the page refreshes and takes me to the top part of the page. Instead, i want to see the part of the page that has the link. It should automatically scroll down to that part once the page refreshes. How is that possible.

我有一个很长的asp.net页面。页面中的HTML表格有一个链接。单击链接时,页面将刷新并将我带到页面的顶部。相反,我想看到页面中有链接的部分。页面刷新后,它应自动向下滚动到该部分。怎么可能。

Really appreciate your help. Thank you!

非常感谢您的帮助。谢谢!

3 个解决方案

#1


1  

If you're using ASP.NET 2.0 or above, and that is a LinkButton doing a postback, you can use:

如果你使用的是ASP.NET 2.0或更高版本,而且这是一个做回发的LinkBut​​ton,你可以使用:

<%@ Page MaintainScrollPositionOnPostback="true" %>

#2


2  

Add MaintainScrollPositionOnPostBack="True" in the page directive.

在页面指令中添加MaintainScrollPositionOnPostBack =“True”。

#3


0  

To color a row you can do this by using HtmlAgilityPack and by using a unique ID per table row, you can do:

要为行着色,可以使用HtmlAgilityPack并使用每个表行的唯一ID来执行此操作,您可以执行以下操作:

HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);

var rows = doc.DocumentNode.SelectNodes("tr");
var linkRow = rows.FirstOrDefault(node =>
{
    HtmlAttribute a = node.Attributes["id"];
    if (null == a) return false;
    return "idLookingFor" == a.Value;
});
linkRow.Attributes.Add("bgcolor", "red"); 

#1


1  

If you're using ASP.NET 2.0 or above, and that is a LinkButton doing a postback, you can use:

如果你使用的是ASP.NET 2.0或更高版本,而且这是一个做回发的LinkBut​​ton,你可以使用:

<%@ Page MaintainScrollPositionOnPostback="true" %>

#2


2  

Add MaintainScrollPositionOnPostBack="True" in the page directive.

在页面指令中添加MaintainScrollPositionOnPostBack =“True”。

#3


0  

To color a row you can do this by using HtmlAgilityPack and by using a unique ID per table row, you can do:

要为行着色,可以使用HtmlAgilityPack并使用每个表行的唯一ID来执行此操作,您可以执行以下操作:

HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);

var rows = doc.DocumentNode.SelectNodes("tr");
var linkRow = rows.FirstOrDefault(node =>
{
    HtmlAttribute a = node.Attributes["id"];
    if (null == a) return false;
    return "idLookingFor" == a.Value;
});
linkRow.Attributes.Add("bgcolor", "red");