1

I have my GridView here .. (Automatically generated as WebForm Template)

I want to create a searchbox wherein I can search all the PTAID ..

Here's my codes

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" ShowFooter="True" OnRowCommand="grdSearch_RowCommand" CssClass="table table-bordered table-hovered">
    <Columns>
        <asp:TemplateField >
            <FooterTemplate>
                 <asp:TextBox ID="text_search" runat="server" CssClass="form-control" />
                <asp:Button ID="btnSearch" CommandName="Search" runat="server" Text="Search" />
            </FooterTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="PTAID" HeaderText="PTAID" SortExpression="PTAID" />
        <asp:BoundField DataField="RequestID" HeaderText="RequestID" SortExpression="RequestID" />
        <asp:BoundField DataField="RequestDate" HeaderText="RequestDate" SortExpression="RequestDate" />
        <asp:BoundField DataField="ProvName" HeaderText="ProvName" SortExpression="ProvName" />
        <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
        <asp:BoundField DataField="INorOUT" HeaderText="INorOUT" SortExpression="INorOUT" />
        <asp:BoundField DataField="Supplier" HeaderText="Supplier" SortExpression="Supplier" />
        <asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer" />
        <asp:BoundField DataField="Program" HeaderText="Program" SortExpression="Program" />
        <asp:BoundField DataField="IssueDesc" HeaderText="IssueDesc" SortExpression="IssueDesc" />
        <asp:BoundField DataField="Chargeable" HeaderText="Chargeable" SortExpression="Chargeable" />
        <asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" />
    </Columns>
</asp:GridView>

How will I make a searchbox ? I tried the one I searched but then i wanted to show the GridView data and the searchbox altogether.

1 Answer 1

1

Please try following code, it should work:

 <div>
    Enter UserName :
<asp:TextBox ID="txtSearch" runat="server" />&nbsp;&nbsp;

<asp:ImageButton ID="btnSearch" text="Search" runat="server"
Style="top: 5px; position: relative; width: 26px;" />&nbsp;&nbsp;
<asp:ImageButton ID="btnClear" text="Clear" runat="server" Style="top: 5px;
position: relative; width: 14px;" /><br />
<br />
</p>
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="False" AllowPaging="True"
AllowSorting="True" DataSourceID="dsDetails" Width="540px" CssClass="Gridview" >
<HeaderStyle BackColor="#df5015" />
<Columns>
  <asp:BoundField DataField="PTAID" HeaderText="PTAID" SortExpression="PTAID" />
        <asp:BoundField DataField="RequestID" HeaderText="RequestID" SortExpression="RequestID" />
        <asp:BoundField DataField="RequestDate" HeaderText="RequestDate" SortExpression="RequestDate" />
        <asp:BoundField DataField="ProvName" HeaderText="ProvName" SortExpression="ProvName" />
        <asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
        <asp:BoundField DataField="INorOUT" HeaderText="INorOUT" SortExpression="INorOUT" />
        <asp:BoundField DataField="Supplier" HeaderText="Supplier" SortExpression="Supplier" />
        <asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer" />
        <asp:BoundField DataField="Program" HeaderText="Program" SortExpression="Program" />
        <asp:BoundField DataField="IssueDesc" HeaderText="IssueDesc" SortExpression="IssueDesc" />
        <asp:BoundField DataField="Chargeable" HeaderText="Chargeable" SortExpression="Chargeable" />
        <asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" />

</Columns>
</asp:GridView>
    </div>
        <asp:SqlDataSource ID="dsDetails" runat="server" ConnectionString="<%$ ConnectionStrings:DemoConnectionString %>" SelectCommand="SELECT [name], [address] FROM [stud_info]" FilterExpression="Name LIKE '%{0}%'">
<FilterParameters>
<asp:ControlParameter Name="PTAID" ControlID="txtSearch" PropertyName="Text" />
</FilterParameters>
</asp:SqlDataSource>
  

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, If this answer help you then please mark as answer.@Anaiah & Jens Horstmann

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.