Dealy

Dealy

  • NA
  • 213
  • 0

Gridview filter when typing on a textbox

Aug 22 2016 3:45 AM
Hello,
 
I have the following code:
  1. <!DOCTYPE html>  
  2.   
  3. <html xmlns="http://www.w3.org/1999/xhtml">  
  4. <head runat="server">  
  5.     <title></title>  
  6.     <style type="text/css">  
  7.         .auto-style1 {  
  8.             width: 4px;  
  9.         }  
  10.     </style>  
  11. </head>  
  12. <body>  
  13.     <form id="form1" runat="server">  
  14.     <div>  
  15.       <table>  
  16. <tr>  
  17.       
  18.     <td class="auto-style2">  
  19.         <asp:Label ID="lblIDNO" runat="server" Text="IDNO:"></asp:Label>  
  20.     </td>  
  21.     <td class="auto-style3">  
  22.        <asp:TextBox ID="srchIDNO" runat="server"></asp:TextBox>  
  23.     </td>  
  24. </tr>  
  25.        <tr>  
  26.            <td>  
  27.                <asp:Label ID="Label1" runat="server" Text="Name: "></asp:Label>  
  28.            </td>  
  29.            <td>  
  30.                <asp:TextBox ID="srchName" runat="server"></asp:TextBox>  
  31.            </td>  
  32.        </tr>  
  33.        </table>  
  34.     <br />   
  35.     <asp:GridView ID="gvDisplay" runat="server" AutoGenerateColumns="false" DataSourceID="SqlDataSource1"  
  36.         DataKeyNames="IDNO" OnRowDataBound="OnRowDataBound" EmptyDataText="Δεν υπάρχουν καταχωρημένες αιτήσεις." >  
  37.         <Columns>  
  38.             <asp:BoundField DataField="IDNO" HeaderText="IDNO" ItemStyle-Width="50" />  
  39.             <asp:BoundField DataField="CName" HeaderText="CName" ItemStyle-Width="80" />  
  40.             <asp:CommandField ButtonType="Link" ShowEditButton="true"    
  41.                 ShowDeleteButton="true" ItemStyle-Width="100" />  
  42.         </Columns>  
  43.     </asp:GridView>  
  44.     <br />  
  45.     <table>  
  46.         <tr>  
  47.             <td class="auto-style1">  
  48.                 IDNO:<br />  
  49.                 <asp:TextBox ID="txtIDNO" runat="server" Width="100" />  
  50.             </td>  
  51.             <td class="auto-style4">  
  52.                Name:<br />  
  53.                 <asp:TextBox ID="txtName" runat="server" Width="200" />  
  54.             </td>  
  55.               
  56.             <td class="auto-style5">  
  57.                 <asp:Button ID="btnAdd" runat="server" Text="Insert" OnClick="Insert" Width="90px" />      
  58.             </td>  
  59.         </tr>  
  60.     </table>  
  61.     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:connectionString %>"   
  62.         DeleteCommand="sprocDelete" DeleteCommandType="StoredProcedure"   
  63.         InsertCommand="sprocInsert" InsertCommandType="StoredProcedure"   
  64.         SelectCommand="sprocSelect" SelectCommandType="StoredProcedure"   
  65.         UpdateCommand="sprocUpdate" UpdateCommandType="StoredProcedure">  
  66.           <SelectParameters>  
  67.               <asp:ControlParameter ControlID="txtIDNO" Name="IDNO" Type="String" />  
  68.              <asp:ControlParameter ControlID="txtName" Name="CName" Type="String" />  
  69.           </SelectParameters>            
  70.         <InsertParameters>  
  71.              <asp:ControlParameter ControlID="txtIDNO" Name="IDNO" Type="String" />  
  72.              <asp:ControlParameter ControlID="txtName" Name="CName" Type="String" />  
  73.         </InsertParameters>  
  74.         <UpdateParameters>  
  75.              <asp:Parameter Name="IDNO" Type="String" />  
  76.              <asp:Parameter Name="CName" Type="String" />  
  77.         </UpdateParameters>  
  78.         <DeleteParameters>  
  79.              <asp:Parameter Name="IDNO" Type="String" />  
  80.         </DeleteParameters>  
  81.   </asp:SqlDataSource>  
  82.     </div>  
  83.     </form>  
  84. </body>  
  85. </html>  
  1. protected void Insert(object sender, EventArgs e)    
  2. {    
  3.     SqlDataSource1.Insert();    
  4.     
  5.     txtIDNO.Text = String.Empty;    
  6.     txtName.Text = String.Empty;    
  7. }    
  8.     
  9. protected void OnRowDataBound(object sender, GridViewRowEventArgs e)    
  10. {    
  11.     if (e.Row.RowType == DataControlRowType.DataRow && gvDisplay.EditIndex != e.Row.RowIndex)    
  12.     {    
  13.         (e.Row.Cells[2].Controls[2] as LinkButton).Attributes["onclick"] = "return confirm('Do you want to delete this row?');";    
  14.     }    
  15. }    
 
How can I filter the gridview while typing on the textboxes? sprocSelect take parameters the IDNO and Name.
 
Thank you in advance. 
 
 

Answers (8)