Click here to Skip to main content
16,010,553 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my application i need to display the search box beside the header column that is beside EmpName but it displays the search box below the employee name.How can i place the search box beside the header of the gridview.The screen shot that had attached shows i am getting the search box below the header EmpName but i should get beside EmpName.How can i do this


ASP.NET
<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 () {
            $('.search_textbox').each(function (i) {
                $(this).quicksearch("[id*=GridView1] tr:not(:has(th))", {
                    'testQuery': function (query, txt, row) {
                        return $(row).children(":eq(" + i + ")").text().toLowerCase().indexOf(query[0].toLowerCase()) != -1;
                    }
                });

 <asp:GridView ID="GridView1" ShowHeader="true" runat="server" AutoGenerateColumns="False" DataKeyNames="EmpId" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDataBound="GridView1_RowDataBound" OnDataBound="GridView1_DataBound" UseAccessibleHeader ="true">
                            <AlternatingRowStyle Width="80px" />
                            <Columns>

                                <asp:BoundField DataField="EmpName" HeaderText="EmpName" ReadOnly="true" ItemStyle-Width="100"  />
                                <asp:BoundField DataField="Designation" HeaderText="Designation" ReadOnly="true" ItemStyle-Width="100" />
                                <asp:BoundField DataField="salary" HeaderText="Salary" ReadOnly="true" ItemStyle-Width="100" />
                                <asp:BoundField DataField="notes" HeaderText="Notes" ItemStyle-Width="150" />

                                <%--                    <asp:CommandField ShowEditButton="true" CancelText="" DeleteText="" EditText='<%#Eval("notes").ToString()=="" ? "add" : "edit" %>' UpdateText='<%# Eval("notes")%>' />--%>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:Button CommandName="Edit" runat="server" Text='<%# (string.IsNullOrEmpty(Eval("notes").ToString()))  ? "Add":"Edit"%>' ID="btnAdd" />
                                        <asp:Button CommandName="Update" Visible="false" runat="server" Text='<%# (string.IsNullOrEmpty(Eval("notes").ToString()))  ? "Save":"Update"%>' ID="btnUpdate" />
                                        <%-- <asp:Button CommandName="Cancel" Visible="false" runat="server" Text="Cancel" ID="btnCancel" />--%>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>

                        </asp:GridView>
            });
        });
    </script>
  protected void GridView1_DataBound(object sender, EventArgs e)
        {
            GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
            //for (int i = 0; i < GridView1.Columns.Count - 1; i++)
            //{
                TableHeaderCell cell = new TableHeaderCell();
                TextBox txtSearch = new TextBox();
                txtSearch.Attributes["Search Box"] = GridView1.Columns[1].HeaderText;
                txtSearch.CssClass = "search_textbox";
                cell.Controls.Add(txtSearch);
                row.Controls.Add(cell);
            //}
            GridView1.HeaderRow.Parent.Controls.AddAt(1, row);
        }
    }


What I have tried:

i had tried the above code but it adds search filter below the header but i need it beside the header
Posted
Updated 15-Nov-16 6:18am
v2

1 solution

Do you have a screen shot? Perhaps you can try using a custom control that extends the DataGridView which already has filtering.
Custom DataGridView for Data Management[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900