2010-11-29 27 views

回答

0

在標題模板上添加一個文本框和按鈕。

在按鈕上寫下查詢並獲取值。

查詢像SELECT * FROM TBL其中山坳LIKE '%VAL%'

綁定價值GridView控件。

我認爲這將解決你

0

ASPX代碼:

<asp:TemplateField> 
        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" /> 
        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="150px" /> 
        <HeaderTemplate> 
         <table> 
          <tr> 
           <td align="center"> 
            <asp:ImageButton runat="server" ID="imgFilter1" ImageUrl="../Images/filter.png" Style="height: 20px; 
             width: 20px;" OnClick="imgFilter1_click" /> 
           </td> 
           <td align="center"> 
            <asp:TextBox runat="server" ID="gridTextboxFilter1" AutoPostBack="true" onTextChanged="gridTextboxFilter1_text_changed"> 
            </asp:DropDownList> 
           </td> 
          </tr> 
          <tr> 
           <td align="center" colspan="2"> 
            //your column header 
           </td> 
          </tr> 
         </table> 
        </HeaderTemplate> 
        <ItemTemplate> 
         <asp:Label runat="server" Text='<%# Eval("your_dataFeild") %>'> 
         </asp:Label> 
        </ItemTemplate> 
       </asp:TemplateField> 

CS代碼:

private void BindGrid(string strFilter) 
     {    
      try 
      { 
       // Simple created a table to bind with Grid view and 
       // populated it with data. 
       DataTable dt = new DataTable("sample"); 
       dt.Columns.Add("ID"); 
       dt.Columns.Add("Name"); 
       DataRow dr ; 
       for(int counter=1;counter<11;counter++) 
       { 
        dr = dt.NewRow(); 
        dr["ID"]=counter.ToString(); 
        dr["Name"]= "Cat" + counter.ToString(); 
        dt.Rows.Add(dr); 
       } 

       DataView dv = new DataView(dt); 
       if(strFilter != "") 
        dv.RowFilter="Name like '%" + strFilter + "%'"; 

       if (CategoryFilter == "") 
        gvCategory.DataSource = dv; 
       else 
        gvCategory.DataSource = dv; 
       gvCategory.DataBind(); 
      } 
      catch (Exception ex) 
      { 

      } 
      finally 
      { 

      } 
     } 

     protected void gridTextboxFilter1_text_changed(object sender, EventArgs e) 
     { 
      string text = ((TextBox)sender).Text; 
      BindGrid(text); 
     } 
+0

使用的每一列 – 2015-03-01 05:15:39

相關問題