搜寻不工作的GridView [英] Search not working on Gridview

查看:135
本文介绍了搜寻不工作的GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现在GridView中搜索列从<一个href=\"http://www.aspsnippets.com/Articles/Search-GridView-records-data-on-TextBox-Key$p$pss-using-jQuery-in-ASPNet.aspx\"相对=nofollow>这个
 链接。我就按照我的requirement.But它不是为我工作。请参阅code,供大家参考: -

I have Implemented the Search on gridview for columns from this link. I implemented as per my requirement.But it is not working for me. Please see the code for your reference:-

 <asp:GridView ID="grdCSRPageData" runat="server" Width="100%" border="1" Style="border: 1px solid #E5E5E5;" CellPadding="3" class="hoverTable" AutoGenerateColumns="false" AllowPaging="True" BackColor="#E5E5E5" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" ForeColor="Black" GridLines="Vertical" ShowFooter="true" PageSize="5" OnPageIndexChanging="grdCSRPageData_PageIndexChanging" OnRowCancelingEdit="grdCSRPageData_RowCancelingEdit" OnRowEditing="grdCSRPageData_RowEditing" OnRowUpdating="grdCSRPageData_RowUpdating" OnRowDeleting="grdCSRPageData_RowDeleting" OnRowCommand="grdCSRPageData_RowCommand" OnDataBound="grdCSRPageData_DataBound">
                <AlternatingRowStyle BackColor="#CCCCCC" />

                <Columns>
                    <asp:BoundField DataField="page_title" HeaderText="Page Title" ItemStyle-Width="30" />
                    <asp:BoundField DataField="page_description" HeaderText="Page Description" ItemStyle-Width="30" />
                    <asp:BoundField DataField="meta_title" HeaderText="Meta Title" ItemStyle-Width="30" />
                    <asp:BoundField DataField="meta_keywords" HeaderText="Meta Keywords" ItemStyle-Width="30" />
                    <asp:BoundField DataField="meta_description" HeaderText="Meta Description" ItemStyle-Width="30" />
                    <asp:CheckBoxField DataField="Active" HeaderText="Active" ItemStyle-Width="15" />
                    <asp:TemplateField HeaderText="Edit/Delete" HeaderStyle-Width="15%">
                        <ItemTemplate>
                            <asp:LinkButton ID="lbtnEdit" runat="server" CommandName="Edit" Text="Edit" />
                            <span onclick="return confirm('Are you sure want to delete?')">
                                <asp:LinkButton ID="btnDelete" Text="Delete" runat="server" CommandName="Delete"></asp:LinkButton>
                            </span>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" />
                            <asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" />
                        </EditItemTemplate>
                        <HeaderTemplate>
                            <asp:Button ID="btnInsertRecord" runat="server" Text="Add" CommandName="Insert" />
                        </HeaderTemplate>
                        <HeaderStyle Width="15%"></HeaderStyle>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

另见JS脚本

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>          
<script type="text/javascript" src="js/quicksearch.js"></script>
<script type="text/javascript">
    $(function () {
        $('.form-control').each(function (i) {
            $(this).quicksearch("[id*=grdCSRPageData] tr:not(:has(th))", {
                'testQuery': function (query, txt, row) {
                    return $(row).children(":eq(" + i + ")").text().toLowerCase().indexOf(query[0].toLowerCase()) != -1;
                }
            });
        });
    });
</script>

另见code背后为你参考: -

Also see the code behind for your ref:-

  protected void grdCSRPageData_DataBound(object sender, EventArgs e)
    {
        GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
        for (int i = 0; i < grdCSRPageData.Columns.Count; i++)
        {
            TableHeaderCell cell = new TableHeaderCell();
            TextBox txtSearch = new TextBox();
            txtSearch.Attributes["placeholder"] = grdCSRPageData.Columns[i].HeaderText;
            txtSearch.CssClass = "form-control";
            cell.Controls.Add(txtSearch);
            row.Controls.Add(cell);
        }
        grdCSRPageData.HeaderRow.Parent.Controls.AddAt(1, row);
    }

网格更改

 protected void grdUser_DataBound(object sender, EventArgs e)
    {
        GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
        for (int i = 0; i < grdUser.Columns.Count; i++)
        {
            TableHeaderCell cell = new TableHeaderCell();
            TextBox txtSearch = new TextBox();
            txtSearch.Attributes["placeholder"] = grdUser.Columns[i].HeaderText;
            txtSearch.CssClass = "form-control HaydaBre";

            if (grdUser.Columns[i].HeaderText != "Action" && grdUser.Columns[i].HeaderText != "" && grdUser.Columns[1].HeaderText != "Select") // && grdUser.Columns[i].HeaderText != "" && grdUser.Columns[i].HeaderText != null && grdUser.Columns[i].HeaderText != "Select")
            {
                cell.Controls.Add(txtSearch);
            }
            row.Controls.Add(cell);
        }
        grdUser.HeaderRow.Parent.Controls.AddAt(1, row);
    }

当我添加了的HeaderText != 选择。它停止了第一列的工作,但它适用于其他列

When I add the HeaderText != Select. It stops working for the first column, but it works for the other column

推荐答案

有很多与表单控件类元素。所以,你可以改变你的C#code是:

There are a lot of elements with form-control class. So can you change your C# code to be:

protected void grdCSRPageData_DataBound(object sender, EventArgs e)
    {
        GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
        for (int i = 0; i < grdCSRPageData.Columns.Count; i++)
        {
            TableHeaderCell cell = new TableHeaderCell();
            TextBox txtSearch = new TextBox();
            txtSearch.Attributes["placeholder"] = grdCSRPageData.Columns[i].HeaderText;
            txtSearch.CssClass = "form-control HaydaBre";
            cell.Controls.Add(txtSearch);
            row.Controls.Add(cell);
        }
        grdCSRPageData.HeaderRow.Parent.Controls.AddAt(1, row);
    }

和您的JS code是:

and your JS code to be:

<script type="text/javascript">
    $(function () {
        $('.HaydaBre').each(function (i) {
            $(this).quicksearch("[id*=grdCSRPageData] tr:not(:has(th))", {
                'testQuery': function (query, txt, row) {
                    return $(row).children(":eq(" + i + ")").text().toLowerCase().indexOf(query[0].toLowerCase()) != -1;
                }
            });
        });
    });
</script> 

这篇关于搜寻不工作的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆