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

Programmatically loading Filter Values

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 16 Mar 2009, 06:05 AM

I am trying to help the user select filter values by clicking on a grid row and then programmatically loading those values into the filter columns.  I have two problems.  My columns are automatically generated and columns are not found in the foreach loop.  Secondly, the CurrentFilterValue does not seem to accept values.

Thanks for any assistance.


 

protected void radGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)

{

 

 

 

 

if (e.CommandName == "RowClick" && e.Item is GridDataItem)

{

 

 

 

foreach (GridColumn column in radGrid1.MasterTableView.Columns)  

{

 

 

 

string IDx = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][column.UniqueName].ToString();

column.CurrentFilterValue = IDx;

}

 

 

 

}

}

 

 

 

 

  

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Mar 2009, 11:41 AM
Hi,

You can use the RenderColumns collection to access the autogenerated columns collection snd set the filter expression for the mastertableview. Check out the code below:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
    {  
        if (e.CommandName == "RowClick" && e.Item is GridDataItem)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns)  
            {  
                if (column is GridBoundColumn)  
                {  
                   string IDx = item[column.UniqueName].Text; 
                   column.CurrentFilterValue = IDx; 
                   column.CurrentFilterFunction = GridKnownFunction.Contains;  
                   RadGrid1.MasterTableView.FilterExpression = "(["+column.UniqueName+"] = " + IDx + ")";                    
                }  
            }  
            RadGrid1.Rebind();  
        }  
    }  

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