Javascript 在Gridview页面中搜索并突出显示文本
我有一个Javascript 在Gridview页面中搜索并突出显示文本,javascript,asp.net,gridview,Javascript,Asp.net,Gridview,我有一个gridview从数据集填充Gridview包含数千条记录,因此我使用dataview实现了分页。填充gridview后,我正在使用java脚本搜索gridview列中的文本,并突出显示文本。它工作到gridview行的末尾 我想实现类似的搜索,应该使用javascript继续到gridview的下一页 function searchback() {//alert(window.opener) var rowid = -1 if (typeof(window.opene
gridview
从数据集填充Gridview
包含数千条记录,因此我使用dataview
实现了分页。填充gridview
后,我正在使用java脚本搜索gridview
列中的文本,并突出显示文本。它工作到gridview
行的末尾
我想实现类似的搜索,应该使用javascript继续到gridview
的下一页
function searchback()
{//alert(window.opener)
var rowid = -1
if (typeof(window.opener) != "undefined" && window.opener != null)
{
i = 1;
if ((document.getElementById('<%= hdn_value.ClientId %>').value!="")&&(document.getElementById('<%= hdn_value.ClientId %>').value!="undefined"))
{
if ((document.getElementById('<%= hdn_ddVal.ClientId %>').value!="")&&(document.getElementById('<%= hdn_ddVal.ClientId %>').value!="undefined"))
{
//alert(document.getElementById('<%= hdn_ddVal.ClientId %>').value)
if (document.getElementById('<%= hdn_ddVal.ClientId %>').value==document.getElementById('colNos').value)
{
i=document.getElementById('<%= hdn_value.ClientId %>').value;
i--;
}
}
}
//alert(i);
var rows = window.opener.document.getElementById(opener.gvwListViewId).getElementsByTagName('tr');
var searchData = document.getElementById('<%= hdn_SearchText.ClientId %>').value.toLowerCase();
//alert(searchData)
var searchExp = new RegExp(searchData);
//alert(searchExp)
var colNo = document.getElementById('colNos').value;
document.getElementById('<%= hdn_ddVal.ClientId %>').value=document.getElementById('colNos').value;
// alert(colNo)
// alert(rows.length)
while(i < rows.length)
{
if(searchExp.test(rows[i].getElementsByTagName('td')[colNo].innerText.toLowerCase()))
{
if (document.getElementById('rbtn_MatchFullWord').checked)
{
if (rows[i].getElementsByTagName('td')[colNo].innerText.toLowerCase().replace(/^\s+|\s+$/g,"")!=searchData.replace(/^\s+|\s+$/g,""))
{
i--;
continue;
}
}
//alert(i)
// rows[i].click();
// alert('done boss')
// rows[i].cells[colNo].blur()
if ((document.getElementById('<%= hdn_value.ClientId %>').value!="")&&(document.getElementById('<%= hdn_value.ClientId %>').value!="undefined"))
{
rows[document.getElementById('<%= hdn_value.ClientId %>').value].cells[colNo].style.backgroundColor=document.getElementById('<%= hdn_backColor.ClientId %>').value;
}
document.getElementById('<%= hdn_backColor.ClientId %>').value=rows[i].cells[colNo].style.backgroundColor;
rows[i].cells[colNo].style.backgroundColor ='yellow';
rows[i].scrollIntoView(false);
document.getElementById('<%= hdn_value.ClientId %>').value = i;
break;
}
i--;
}
// alert("hdn2:"+ document.getElementById('<%= hdn_value.ClientId %>').value);
if (i == 0)
{
if (window.opener.document.getElementById('ctl00_toolbar1_ibtn_Next') != null)
{
if(yesno("Finished searching the current page. Do you want to search in the next page?", "Search") == 6)
{
window.opener.document.getElementById('ctl00_toolbar1_ibtn_Next').click();
}
}
else if (document.getElementById('<%= hdn_value.ClientId %>').value == "")
{
alert("Search Completed No Records Found");
}
else
{
alert('Search Completed');
}
}
}
// alert('outside if');
if (rowid != -1)
{
// alert('rowid'+rowid)
window.returnValue = rowid;
window.close;
}
}
gridivew寻呼机控件添加到面板中,使其与gridview分离
搜索功能是从弹出窗口执行的。我通过弹出窗口中的javascript访问面板中的控件,如下所示。但它返回的长度为零
var controls = window.opener.document.getElementById('ctl00_ContentPlaceHolder1_pnlpager1').getElementsByTagName("input");
alert(controls.length);
for (var i = 0; i < controls.length; i++)
alert(controls[i]);
var controls=window.opener.document.getElementById('ctl00_ContentPlaceHolder1_pnlpager1')。getElementsByTagName(“输入”);
警报(控制长度);
对于(变量i=0;i
我们可以使用javascript在gridview的所有页面中搜索gridview列吗
请检查javascript中的代码
function searchback()
{//alert(window.opener)
var rowid = -1
if (typeof(window.opener) != "undefined" && window.opener != null)
{
i = 1;
if ((document.getElementById('<%= hdn_value.ClientId %>').value!="")&&(document.getElementById('<%= hdn_value.ClientId %>').value!="undefined"))
{
if ((document.getElementById('<%= hdn_ddVal.ClientId %>').value!="")&&(document.getElementById('<%= hdn_ddVal.ClientId %>').value!="undefined"))
{
//alert(document.getElementById('<%= hdn_ddVal.ClientId %>').value)
if (document.getElementById('<%= hdn_ddVal.ClientId %>').value==document.getElementById('colNos').value)
{
i=document.getElementById('<%= hdn_value.ClientId %>').value;
i--;
}
}
}
//alert(i);
var rows = window.opener.document.getElementById(opener.gvwListViewId).getElementsByTagName('tr');
var searchData = document.getElementById('<%= hdn_SearchText.ClientId %>').value.toLowerCase();
//alert(searchData)
var searchExp = new RegExp(searchData);
//alert(searchExp)
var colNo = document.getElementById('colNos').value;
document.getElementById('<%= hdn_ddVal.ClientId %>').value=document.getElementById('colNos').value;
// alert(colNo)
// alert(rows.length)
while(i < rows.length)
{
if(searchExp.test(rows[i].getElementsByTagName('td')[colNo].innerText.toLowerCase()))
{
if (document.getElementById('rbtn_MatchFullWord').checked)
{
if (rows[i].getElementsByTagName('td')[colNo].innerText.toLowerCase().replace(/^\s+|\s+$/g,"")!=searchData.replace(/^\s+|\s+$/g,""))
{
i--;
continue;
}
}
//alert(i)
// rows[i].click();
// alert('done boss')
// rows[i].cells[colNo].blur()
if ((document.getElementById('<%= hdn_value.ClientId %>').value!="")&&(document.getElementById('<%= hdn_value.ClientId %>').value!="undefined"))
{
rows[document.getElementById('<%= hdn_value.ClientId %>').value].cells[colNo].style.backgroundColor=document.getElementById('<%= hdn_backColor.ClientId %>').value;
}
document.getElementById('<%= hdn_backColor.ClientId %>').value=rows[i].cells[colNo].style.backgroundColor;
rows[i].cells[colNo].style.backgroundColor ='yellow';
rows[i].scrollIntoView(false);
document.getElementById('<%= hdn_value.ClientId %>').value = i;
break;
}
i--;
}
// alert("hdn2:"+ document.getElementById('<%= hdn_value.ClientId %>').value);
if (i == 0)
{
if (window.opener.document.getElementById('ctl00_toolbar1_ibtn_Next') != null)
{
if(yesno("Finished searching the current page. Do you want to search in the next page?", "Search") == 6)
{
window.opener.document.getElementById('ctl00_toolbar1_ibtn_Next').click();
}
}
else if (document.getElementById('<%= hdn_value.ClientId %>').value == "")
{
alert("Search Completed No Records Found");
}
else
{
alert('Search Completed');
}
}
}
// alert('outside if');
if (rowid != -1)
{
// alert('rowid'+rowid)
window.returnValue = rowid;
window.close;
}
}
函数searchback()
{//alert(window.opener)
var rowid=-1
if(typeof(window.opener)!=“未定义”&&window.opener!=null)
{
i=1;
if((document.getElementById(“”).value!=“”)和&(document.getElementById(“”).value!=“未定义”))
{
if((document.getElementById(“”).value!=“”)和&(document.getElementById(“”).value!=“未定义”))
{
//警报(document.getElementById(“”).value)
if(document.getElementById(“”).value==document.getElementById('colNos').value)
{
i=document.getElementById(“”).value;
我--;
}
}
}
//警报(一);
var rows=window.opener.document.getElementById(opener.gvListViewId).getElementsByTagName('tr');
var searchData=document.getElementById(“”).value.toLowerCase();
//警报(搜索数据)
var searchExp=新的RegExp(searchData);
//警报(searchExp)
var colNo=document.getElementById('colNos')。值;
document.getElementById(“”).value=document.getElementById('colNos').value;
//警报(科尔诺)
//警报(行数。长度)
while(i
你能把你写的代码贴出来吗……那会很有帮助的……我已经添加了代码。请检查代码您是否使用客户端分页技术?