Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery对页面中包含的用户控件进行Gridview筛选_Jquery_Asp.net_.net - Fatal编程技术网

使用jQuery对页面中包含的用户控件进行Gridview筛选

使用jQuery对页面中包含的用户控件进行Gridview筛选,jquery,asp.net,.net,Jquery,Asp.net,.net,我已将我的用户控件(my.ascx)放在网页(1.aspx)上。my.ascx包含gridview、搜索文本框和搜索按钮。 我需要根据我在搜索按钮单击事件的搜索文本框中键入的文本在gridview中显示行。以下是我所做的 在1.aspx中: <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script> <script type="text/javascript" language

我已将我的用户控件(my.ascx)放在网页(1.aspx)上。my.ascx包含gridview、搜索文本框和搜索按钮。 我需要根据我在搜索按钮单击事件的搜索文本框中键入的文本在gridview中显示行。以下是我所做的

在1.aspx中:

<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$('#lblNoRecords').css('display','none');

$('#btnSubmit').click(function(e)
{
    // Hide No records to display label.
    $('#lblNoRecords').css('display','none'); 
    //Hide all the rows.
    $("#GridView1 tr:has(td)").hide(); 

    var iCounter = 0;
    //Get the search box value
    var sSearchTerm = $('#txtSearch').val(); 

    //if nothing is entered then show all the rows.
    if(sSearchTerm.length == 0) 
    {
      $("#GridView1 tr:has(td)").show(); 
      return false;
    }
    //Iterate through all the td.
    $("#GridView1 tr:has(td)").children().each(function() 
    {
        var cellText = $(this).text().toLowerCase();
        //Check if data matches
        if(cellText.indexOf(sSearchTerm.toLowerCase()) >= 0) 
        {    
            $(this).parent().show();
            iCounter++;
            return true;
        } 
    });
    if(iCounter == 0)
    {
        $('#lblNoRecords').css('display','');
    }
    e.preventDefault();
})
})
</script>

$(文档).ready(函数(){
$('lblNoRecords').css('display','none');
$('#btnsupmit')。单击(函数(e)
{
//隐藏任何记录以显示标签。
$('lblNoRecords').css('display','none');
//隐藏所有行。
$(“#GridView1 tr:has(td)”).hide();
var iCounter=0;
//获取搜索框的值
var ssearch term=$('#txtSearch').val();
//如果未输入任何内容,则显示所有行。
如果(sSearchTerm.length==0)
{
$(“#GridView1 tr:has(td)”).show();
返回false;
}
//遍历所有td。
$(“#GridView1 tr:has(td)”).children().each(function())
{
var cellText=$(this.text().toLowerCase();
//检查数据是否匹配
if(cellText.indexOf(sSearchTerm.toLowerCase())>=0)
{    
$(this.parent().show();
iCounter++;
返回true;
} 
});
如果(i计数器==0)
{
$('lblNoRecords').css('display','');
}
e、 预防默认值();
})
})
在my.ascx中:

<asp:TextBox ID="txtSearch" runat="server" ClientIDMode="Static"
                meta:resourcekey="txtSearchResource1"></asp:TextBox>

<asp:Button ID="btnSubmit"  runat="server" ClientIDMode="Static" CssClass ="ButtonNormal" Text="Search" 
                meta:resourcekey="btnSubmitResource1" /> 

<asp:Label ID="lblNoRecords" runat="server" ClientIDMode="Static" 
                meta:resourcekey="lblNoRecordsResource1"></asp:Label>
<gridview ..........
......


尝试从以下位置替换Gridview ID的jQuery选择器实例:

 $("#GridView1 tr:has(td)")

$(“#tr:has(td)”)
 $("#<%= GridView1.ClientID %> tr:has(td)")