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

Determine Column ID of Filtered Column

1 Answer 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nathan
Top achievements
Rank 2
Nathan asked on 05 Feb 2012, 04:12 AM
Hello,

I'm using filtering on my grid. When the user selects a filter the "Item_Command" event is triggered where I can retrieve the Filter pair from the command argument. From this argument I can get the "filterPair.first", "filterPair.second", ..etc. Using this approach I can get access to the column name that the user is filtering, but I need the associated Column ID. Is it possible to associate more data with this filter or command argument? Maybe I could add an attribute to the filter Textbox when the filter is created, then read it on ItemCommand? 

Please let me know if you have suggestions on the best approach.

protected void grdSummary_ItemCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.FilterCommandName)
    {
        Pair filterPair = (Pair)e.CommandArgument;
 
        string strOperator = filterPair.First;    // Starts With, ..etc
        string strColumn = filterPair.Second;    // Column Filtering On
        string searchValue = ((TextBox)(e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[0]).Text;
           string columnId = ?? 

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 07 Feb 2012, 02:33 PM
Hi Nathan,

I am not sure what you mean by column id but anyhow once you get the GridColumn object which you are filtering on you can easily retrieve any column properties. Any you get the GridColumn object being filtered on in the following way: as you have correctly noted the e.CommandArgument comes with a pair of two strings; the second one contains the DataField for the filtered column; having the data field you can retrieve the column as follows:
RadGrid1.MasterTableView.Columns.FindByDataField("ProductName");

Hope it helps.


All the best, Tsvetoslav
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Grid
Asked by
Nathan
Top achievements
Rank 2
Answers by
Tsvetoslav
Telerik team
Share this question
or