title: C# add filter parameters and expression to listview dynamically
body: <p>I would like to dynamically set filtering of listview based on textboxes since I implicitly don't know the number and names of collumns. I've made it by creating Texboxes, setting filterparams and filterexpression in code behind - page is loading and working without any error but after changing text in any of textboxes listview is not filtering. When debuging I see that all filterexpression and filtercontrols exist with attributes I would expect. I really can't see any error and would appriciate any help. Thanks!</p>
  
  <p>On Page_Load I have following code:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
  
      // some code where I get datatable for my listview 
      // and put columns to tablecols
  
          tablecols = dtable.Columns;
  
  
  
      // creating of htmltablerow with textboxes for filtering
  
          HtmlTableRow htr_filterrow = new HtmlTableRow();
          htr_filterrow.ID = "filterrow"; 
  
          foreach (DataColumn col in tablecols)
          {
              HtmlTableCell htc = new HtmlTableCell();
              TextBox tb = new TextBox();
              tb.ID = "tb_" + col.ColumnName;
  
              htc.Controls.Add(tb);
              htr_filterrow.Controls.Add(htc);
          }
  
          placeholder_filterrow.Controls.Add(htr_filterrow);
  
  
  
      // setting filterparameters of my listview
  
          if (SqlDataSource1.FilterParameters.Count == 0)
          {
              foreach (DataColumn col in tablecols)
              {
                  ControlParameter filter_par = new ControlParameter();
                  filter_par.Name = col.ColumnName;
                  filter_par.ControlID = "ListView1$tb_" + col.ColumnName + "";
                  filter_par.PropertyName = "Text";
                  SqlDataSource1.FilterParameters.Add(filter_par);
              }
          }
  
  
  
     // setting filterexpression for my listview
  
          string filter_express = "";
          int i = 0;
  
          foreach (DataColumn col in tablecols)
          {
              if (filter_express.Length == 0)
              {
                  filter_express = filter_express + " ([" + col.ColumnName + "] like '*{" + i + "}*' or [" + col.ColumnName + "] is null)";
              }
              else
                  filter_express = filter_express + " and ([" + col.ColumnName + "] like '*{" + i + "}*' or [" + col.ColumnName + "] is null)";
              i = ++i;
          }   
  
              SqlDataSource1.FilterExpression = filter_express;
  
      }
  </code></pre>