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

[Solved] Custom filtering problem using rad grid

3 Answers 267 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vivek
Top achievements
Rank 1
vivek asked on 27 Jun 2008, 07:20 PM
I have a rad grid and use drop down lists( three of them) as filter options.

The filtering works fine, but when i select the first item from the drop down list

the selectindexchanged method doesnt fire.

But when i go to the other drop down (say number 2) select something ..

and then go back to the previos drop down and select the first one .. it does fire...


so to rectify this i used radcombo box which corrected my previos issue.

Bt a new problem sprung up... when i filter by one drop down and go and filter by the second drop down the value selected on the first drop down goes back to its default value.. this wasnt the problem when i was using normal drop downs..

Is there any way i can do this ... iam open to using either of them...

thanks...

3 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 30 Jun 2008, 01:16 PM
Hello Vivek,

Both approaches should worked for you. The problem with the first approach (using DropDownList), where the first DropDownList is not firing, is probably due to initialization of the DropDownList in the page lifecylcle. It seems the first DDL has its autopostback property registered after the second DDL has posted back.

As for the second approach, it seems that RadComboBox is reinitialized with a default value every time after a postback, thus setting RadGrid's FilterExpression to "", the result of which is removing the filtering for the first RadComboBox. Please see how you can persist the selected value of RadComboBox over the page postbacks, so that RadGrid does not reset its filtering.

Best wishes,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
vivek
Top achievements
Rank 1
answered on 30 Jun 2008, 02:22 PM
Hi Veli.,

Thanks for the reply.
Regarding the first approach, the DDL1 shouldnt fire its selected index changed then even when i select number 2 item in the list, but it does. it jst doesnt fire when i select the first item.

As for the second approach i jst the code is the same, just changed the control to radcombo box. so i was wondering why the selected value doesnt persist for this control and selected index changed event does fire for the first one.

Here is the code if it helps....

  protected override void SetupFilterControls(System.Web.UI.WebControls.TableCell cell)
        {
            RadComboBox DropDownList1 = new RadComboBox();
            DropDownList1.Width = Unit.Percentage(100);
            DropDownList1.AutoPostBack = true;

         
    

            switch (this.DataField)
            {
                case "RecordTypeName":
                    DropDownList1.ID = "IpTypeList1";

              DropDownList1.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(DropDownList1_SelectedIndexChanged);
                        DropDownList1.DataBound += new EventHandler(DropDownList1_DataBound);
                        DropDownList1.DataSource = recordTypes;
                        DropDownList1.DataTextField = "key";
                        DropDownList1.DataValueField = "key";
                      
                   

                    break;

                case "SubjectStatus":
                    DropDownList1.ID = "SubjectStatusList1";

               
                        DropDownList1.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(DropDownList1_SelectedIndexChanged);
                        DropDownList1.DataBound += new EventHandler(DropDownList1_DataBound);
                        DropDownList1.DataSource = // list object data source
                        DropDownList1.DataTextField = "StatusName";
                        DropDownList1.DataValueField = "StatusName";
                      

                    }
                   
                    break;

                case "PriorityTypeName":
                    DropDownList1.ID = "PriorityTypeList1";

                        DropDownList1.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(DropDownList1_SelectedIndexChanged);
                        DropDownList1.DataBound += new EventHandler(DropDownList1_DataBound);
                 
                        DropDownList1.DataSource = // list object datasource
                        DropDownList1.DataTextField = "PriorityTypeName";
                        DropDownList1.DataValueField = "PriorityTypeName";


                    }
                    break;

              
            }
            cell.Controls.AddAt(0, DropDownList1);
            DropDownList1.DataBind();
        }

        protected override void SetCurrentFilterValueToControl(TableCell cell)
        {
           
                    list.SelectedValue = this.CurrentFilterValue;
           
        }


        protected override string GetCurrentFilterValueFromControl(TableCell cell)
        {
            string currentValue;
            RadComboBox currentList = (RadComboBox)cell.Controls[0];
            string viewStateListId;
            viewStateListId = currentList.ID;
        
            currentValue = currentList.SelectedItem.Value;
        
            this.CurrentFilterFunction = (currentValue != "") ? GridKnownFunction.EqualTo : GridKnownFunction.NoFilter;
            return currentValue;
        }

        protected override string GetFilterDataField()
        {
            return this.DataField;
        }


        protected void DropDownList1_DataBound(object sender, EventArgs e)
        {
            RadComboBox test = (RadComboBox)sender;
            test.Items.Insert(0, new RadComboBoxItem(string.Empty, string.Empty));
        }


        protected void DropDownList1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) //EventArgs e)
        {
            GridFilteringItem filterItem = (sender as RadComboBox).NamingContainer as GridFilteringItem;
            if (this.DataType == System.Type.GetType("System.Int32") ||
                this.DataType == System.Type.GetType("System.Int16") ||
                this.DataType == System.Type.GetType("System.Int64"))
            {
                filterItem.FireCommandEvent("Filter", new Pair("EqualTo", this.UniqueName));
            }
            else // treat everything else like a string
                filterItem.FireCommandEvent("Filter", new Pair("Contains", this.UniqueName));
        }

0
Veli
Telerik team
answered on 01 Jul 2008, 08:53 AM
Hello Vivek,

The code you provided seems fine too. Could you please check where do you call SetupFilterControls(cell) method. Try setting up your filter controls in the ItemDataBound event of RadGrid where you can get your FilteringItem. Another option would be to set up in the PreRender event of RadGrid, but you will need to call RadGrid1.Rebind() at the end.

Kind regards,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
vivek
Top achievements
Rank 1
Answers by
Veli
Telerik team
vivek
Top achievements
Rank 1
Share this question
or