1

我正在使用 ASP.NET 和 C#。这是我的代码。

<asp:UpdatePanel ID="gridSearch" runat="server">
   <ContentTemplate>
      <asp:GridView ID="jobcardSearch" runat="server">                     
          <Columns>
             <asp:TemplateField>                
                <HeaderTemplate>                                                
                   <asp:LinkButton ID="LinkButton1" Text="First Name"
                   CommandName="sort" CommandArgument="FirstName" 
                   runat="server"></asp:LinkButton>                                                                 
                   <asp:TextBox ID="search" runat="server" Width="70px"></asp:TextBox>
               </HeaderTemplate>
               <ItemTemplate>
                  <%# Eval("FirstName")%>
               </ItemTemplate>
             </asp:TemplateField>       
           </Columns>
        </asp:GridView>
   </ContentTemplate>
</asp:UpdatePanel>

因此,在文本框上输入时,我需要过滤网格,然后我需要在不回发的情况下执行此操作。

4

2 回答 2

2

您需要使用 jQuery 或 JavaScript 来完成,而不是为此使用 asp.net ajax 面板。这篇文章可能会对你有所帮助。

于 2012-11-15T12:12:08.680 回答
0

使用jquery处理文本框的按键事件并调用jquery函数然后调用webmethod并将文本框值传递给webmethod,然后根据搜索文本过滤数据库中的数据并将结果绑定到gridview。

供参考检查以下链接:

http://shibashishdotnetocean.blogspot.in/2012/07/autocomplete-text-using-jquery-and-web.html

您还可以在 javascript 中使用 pagemethod 来调用 webmethod 而不是 jquery web 服务调用。

在上面的链接中,唯一的改变是在您的 aspx.cs 页面中添加GetAllEmployees webmethod ,而不是创建 Web 服务。

还将 ScriptManager 的 EnablePageMethods 设为 true。

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />

对于页面方法,请使用以下链接:

http://decoding.wordpress.com/2008/11/14/aspnet-how-to-call-a-server-side-method-from-client-side-javascript/

于 2012-11-15T12:19:20.693 回答