生成Gridview数据后创建Searchbox

时间:2015-06-17 05:43:56

标签: c# asp.net gridview

我在这里GridView ..(自动生成为WebForm模板)

我想创建一个搜索框,我可以搜索所有PTAID ..

这是我的代码

<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>

我如何制作搜索框?我尝试了我搜索的那个,但后来我想要显示GridView数据和搜索框。

1 个答案:

答案 0 :(得分:1)

请尝试以下代码,它应该有效:

 <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>