我的应用程序向用户发送电子邮件,其中包含一个 aspx 页面的超链接。获取字符串中有一个 guid。aspx 页面显示跨多个页面的网格视图。我的要求是单击链接时,应将用户定向到适当的页面,并且应突出显示映射到 guid 的行?
请帮忙,很紧急。
我的应用程序向用户发送电子邮件,其中包含一个 aspx 页面的超链接。获取字符串中有一个 guid。aspx 页面显示跨多个页面的网格视图。我的要求是单击链接时,应将用户定向到适当的页面,并且应突出显示映射到 guid 的行?
请帮忙,很紧急。
Canavar 有一点,但是对于一个简单的事情,你可以承担 RowDataBound 方法的负载,并在渲染结束时执行高亮。
让我们想象一下(因为您没有提供任何有关它的信息 - 顺便说一句,请始终向我们提供问题的最详细版本):)
GridView 显示了 30 行,我们需要突出显示行 ID 22。
请按照以下步骤操作:
1 - 添加一个隐藏字段
<asp:HiddenField ID="rowID" CssClass="rowids" Value='<%# Eval("YourROWID") %>' />
2 - 现在我们有了行,我们需要的是,当 DOM 准备好时,循环遍历所有行并突出显示与您在评论中提到的选择行具有相同值的行
你在使用 jQuery 吗?
var selectedRow = '<%= Request["selectrow"] %>';
$(document).ready(function(){
$(".rowids").each( function() { // Get and Loop through all class=rowids elements
if( $(this).value() == selectedRow) {
// we found it! lets find the TR and add the highlight class to it
$(this) // the INPUT ELEMENT
.parent() // the TD element
.parent() // the TR element
.addClass("highlight"); // Add the class
}
});
});
如果不使用jQuery(你应该这样做,因为我几乎可以肯定你会在其他地方重新使用它来改进代码中的更多部分)
var selectedRow = '<%= Request["selectrow"] %>';
var arr = document.getElementsByTagName("input");
for (i = 0; i < arr.length; i++) { // Loop through all input elements
if( arr[i].className == "rowids" && arr[i].defaultValue == selectedRow ) {
// it's a rowids element and the value is the one we are looking out
var tableRow = arr[i].parentNode.parentNode; // get it's TR element
tableRow.className = tableRow.className + ' hightlight'; // Add the class
break; // no need to loop through more, we already found the one we are looking for
}
}
记得在脚本中的 BODY 标记之前添加它,这样当页面中呈现所有元素时会调用它(DOM 准备技巧)
您可以为此使用 JQuery。
$("a").click(function(){
$(this).effect("highlight", {}, 3000);
})
事情就这么简单。希望能帮助到你。