2012-01-24 12 views
0

私は顧客情報を表示するグリッドビューを持っています。ユーザーが最初と最後のどちらかの名前をテキストボックスに入力すると結果が更新されます。基本的に、グリッドビューへのデータバインディングには、ユーザータイプとしてのテキストボックスからの更新された文字を使用したデータソースです。DataBind GridView OnKeyUp/Down

CODE EDITED:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Process.aspx.cs" Inherits="Reservations.WebForm3" %> 

<asp:UpdateProgress ID="UpdateProgress1" runat="server" 
     AssociatedUpdatePanelID="UpdatePanel1"> 
     <ProgressTemplate>Processing...</ProgressTemplate> 
</asp:UpdateProgress> 
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <ContentTemplate> 
     <asp:TextBox ID="firstname" runat ="server" class="inputLarge" ontextchanged="firstname_TextChanged" /> 
     <asp:TextBox ID="lastname" runat="server" class="inputLarge" /> 

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="457px"> 
       <Columns> 
        <asp:TemplateField> 
         <EditItemTemplate> 
          <asp:CheckBox ID="CheckBox1" runat="server" /> 
         </EditItemTemplate> 
         <ItemTemplate> 
          <asp:CheckBox ID="CheckBox1" runat="server" /> 
         </ItemTemplate> 
         <ItemStyle HorizontalAlign="Center" /> 
        </asp:TemplateField> 
        <asp:BoundField DataField="CustID" HeaderText="Cust ID"> 
        <ItemStyle HorizontalAlign="Center" /> 
        </asp:BoundField> 
        <asp:BoundField DataField="FirstName" HeaderText="First Name"> 
        <ItemStyle HorizontalAlign="Center" /> 
        </asp:BoundField> 
        <asp:BoundField DataField="LastName" HeaderText="Last Name"> 
        <ItemStyle HorizontalAlign="Center" /> 
        </asp:BoundField> 
        <asp:BoundField DataField="City" HeaderText="City"> 
        <ItemStyle HorizontalAlign="Center" /> 
        </asp:BoundField> 
       </Columns> 
      </asp:GridView> 
      <asp:ScriptManager ID="ScriptManager1" runat="server"> 
      <Scripts></Scripts> 
      </asp:ScriptManager> 
     </ContentTemplate> 
     <Triggers> 
      <asp:AsyncPostBackTrigger ControlID="firstname" EventName="TextChanged" /> 
     </Triggers> 
    </asp:UpdatePanel> 


protected void firstname_TextChanged(object sender, EventArgs e) 
    { 
     InventoryAppSoapClient inst = new InventoryAppSoapClient(); 
     DataSet ds = inst.getCustomer(firstname.Text, "none"); 
     GridView1.DataSource = ds; 
     GridView1.DataBind();   
    } 

すべては初回のみ、初めてTextChangedイベントを除いて動作します。私が戻ってテキストとタブを変更すると、何も起こりません。

答えて

0

テキストボックスのOnTextChangedイベントのイベントハンドラを追加しようとしましたか。あなたがそう

Private void firstName_OnTextChanged(object sender, EventArgs e) 
{ 
//Your datasource and parameters are already defined on the front end so there is no 
//setup required 
existing.DataBind(); 
} 

同じ

Private void lastName_OnTextChanged(object sender, EventArgs e) 
{ 
//Your datasource and parameters are already defined on the front end so there is no 
//setup required 
existing.DataBind(); 
} 

lastNameの

テキストボックスのために行くようにデータバインドを強制する可能性があり、各テキストボックスにためOnTextChange属性にメソッドを追加することを忘れないでください内部

フロントエンド。そのようです。

<asp:TextBox ID="firstname" OnTextChanged="firstName_OnTextChanged" runat ="server" class="inputLarge"/> 
<asp:TextBox ID="lastname" OnTextChanged="lastName_OnTextChanged" runat="server" class="inputLarge" /> 

また、このコードを更新パネルに埋め込み、AJAXコントロールツールキット(無料)を使用すると、グリッドがシームレスに更新されます。それ以外の場合は、古典的なASP技術を使用するときれいになりません。このページは、キーを押すたびにポストバックされ続けます。それは迷惑になるでしょう。

+0

私はそれを考えましたが、ユーザタイプとしてグリッドを更新したいと思います。 onTextChangedは、テキストボックスのフォーカスが失われるまで発生しません。 onKeyUpとonKeyDownイベントを使用してJavaScriptやJQueryでバインドする方法はありますか? – jmease

+0

私はあなたの提案をしていますが、gridviewはfirstname_OnTextChanged()イベントのexisting.DataBind()呼び出しに応答しません。データソースを設定するときにクエリをテストしたので、結果が返されるはずです。 gridviewが最初は空だったので、多分苦労していますか? – jmease

+0

グリッドビューは更新パネルにありますか? – gsirianni