This is a migrated thread and some comments may be shown as answers.

Question about creating filter column

1 Answer 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 31 Oct 2011, 09:02 PM
Hi,
I am working on creating custom filtering column for RadGrid, my code is largely based on :
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandcombo/defaultcs.aspx?product=grid

But I would like to have a clear filter button attached to each column, and if the button is clicked it will only clear one column instead of all columns. Here is my overrided function 
protected override void SetupFilterControls(TableCell cell)
{
    base.SetupFilterControls(cell);
    cell.Controls.RemoveAt(0);
    RadComboBox combo = new RadComboBox();
    combo.ID = ("RadComboBox1" + this.UniqueName);
    combo.ShowToggleImage = false;
    //combo.Skin = "Office2007";
    combo.EnableLoadOnDemand = true;
    combo.AutoPostBack = true;
    combo.MarkFirstMatch = true;
    combo.Height = Unit.Pixel(100);
    combo.ItemsRequested += this.list_ItemsRequested;
    combo.SelectedIndexChanged += this.list_SelectedIndexChanged;
    cell.Controls.AddAt(0, combo);
 
    ImageButton button = new ImageButton();
    button.ImageUrl = "~/images/delete.gif";
    button.Click += this.button_Click;
    button.CssClass = "ClearButton";
    cell.Controls.AddAt(1, button);
 
    cell.Controls.RemoveAt(2);
}
What should I do inside button_Click handler?

TIA

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Nov 2011, 06:36 AM
Hello Matt,

You can try the following code snippet.
C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridFilteringItem)
 {
 GridFilteringItem dataItem = (GridFilteringItem)e.Item;
 foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
 {
  Button btn1 = new Button();
  dataItem[col.UniqueName].Controls.Add(btn1);
  btn1.Text = "Clear";
  btn1.Click+=new EventHandler(btn1_Click);
 }
 }
}
void  btn1_Click(object sender, EventArgs e)
{
 GridFilteringItem itm = (GridFilteringItem)RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0];
 foreach (GridColumn col in RadGrid1.MasterTableView.RenderColumns)
 {
  if (col is GridBoundColumn)
  {
  TextBox txt = itm[col.UniqueName].Controls[0] as TextBox;
  if (txt.Text !=  string.Empty)
   {
   txt.Text = "";
   }
  }
 }
 foreach (GridColumn column in RadGrid1.MasterTableView.Columns)
 {
  column.CurrentFilterFunction = GridKnownFunction.NoFilter;
  column.CurrentFilterValue = string.Empty;
 }
 RadGrid1.MasterTableView.FilterExpression = string.Empty;
 RadGrid1.MasterTableView.Rebind();
}

Thanks,
Princy.
Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or