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

RadCombobox inside RadGrid filter template (Selection out of range Parameter name: value)

5 Answers 528 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sergey
Top achievements
Rank 1
Sergey asked on 30 Mar 2015, 01:15 PM
I'm expiriencing the following problem

I have Grid and 2 filters. Second filter is being filled based on selected value in first one.

Here is the code
protected void OnItemCreated(object sender, GridItemEventArgs e)
{
    GridFilteringItem item = e.Item as GridFilteringItem;
 
    if (item != null)
    {
        RadComboBox planIdCombo = (RadComboBox)item.FindControl("planIdFilterComboBox");
        RadComboBox pbpIdCombo = (RadComboBox)item.FindControl("pbpIdFilterComboBox");
 
        planIdCombo.DataSource = SNPConfigView.Select(t => t.PlanID).Distinct().OrderBy(t => t);
        planIdCombo.DataBind();
        planIdCombo.SelectedValue = e.Item.OwnerTableView.GetColumn("PlanId").CurrentFilterValue;
 
        pbpIdCombo.DataSource =  SNPConfigView.Where(t => t.PlanID == planIdCombo.SelectedValue || string.IsNullOrEmpty(planIdCombo.SelectedValue)).Select(t => t.PBPID).Distinct().OrderBy(t => t);
        pbpIdCombo.DataBind();
        pbpIdCombo.SelectedValue = e.Item.OwnerTableView.GetColumn("PbpId").CurrentFilterValue;
    }
}

All is working fine untill you change First filter selected value (in case value in second filter was changed). It throws "Selection out of range Parameter name: value".

I even tried to add items to the second combobox manually (instead of binding it). In this case on code behind it doesn't throw exception but it does throw it on client side (javascript). Error is the same.

I've tried almost everything but still cannot make it work.

<telerik:GridBoundColumn DataField="PlanId" HeaderText="Plan ID" UniqueName="PlanId"  AutoPostBackOnFilter="true"      CurrentFilterFunction="EqualTo" ShowFilterIcon="false" FilterControlWidth="70px">
                                    <ItemStyle CssClass="center"></ItemStyle>
                                    <FilterTemplate>
                                        <telerik:RadComboBox ID="planIdFilterComboBox" Width="60" AppendDataBoundItems="True" OnItemDataBound="OnPlanIdFilterComboItemDataBound" SelectedValue='<%# Container.OwnerTableView.GetColumn("PlanId").CurrentFilterValue %>' runat="server" OnClientSelectedIndexChanged="PlanIdFilterComboIndexChanged">
                                            <Items>
                                                <telerik:RadComboBoxItem Text="All" Value="" />
                                            </Items>
                                        </telerik:RadComboBox>
                                        <telerik:RadScriptBlock ID="planIdFilteringScripBlock" runat="server">
                                            <script type="text/javascript">
                                                function PlanIdFilterComboIndexChanged(sender, args) {
                                                    var tableView = $find("<%# Container.OwnerTableView.ClientID %>");
                                                    tableView.filter("PlanId", args.get_item().get_value(), "EqualTo");
                                                }
                                            </script>
                                        </telerik:RadScriptBlock>
                                    </FilterTemplate>
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="PBPID" HeaderText="PBP" UniqueName="PBPID" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" FilterControlWidth="40px">
                                    <HeaderStyle Width="70px"></HeaderStyle>
                                    <ItemStyle CssClass="center"></ItemStyle>
                                    <FilterTemplate>
                                        <telerik:RadComboBox ID="pbpIdFilterComboBox" Width="60" EnableViewState="False" OnItemDataBound="OnPbpIdFilterComboItemDataBound" SelectedValue='<%# Container.OwnerTableView.GetColumn("PBPID").CurrentFilterValue %>' runat="server" OnClientSelectedIndexChanged="PbpIdFilterComboIndexChanged">
                                              
                                        </telerik:RadComboBox>
                                        <telerik:RadScriptBlock ID="pbpIdFilteringScripBlock" runat="server">
                                            <script type="text/javascript">
                                                function PbpIdFilterComboIndexChanged(sender, args) {
                                                    var tableView = $find("<%# Container.OwnerTableView.ClientID %>");
                                                    tableView.filter("PBPID", args.get_item().get_value(), "EqualTo");
                                                }
                                            </script>
                                        </telerik:RadScriptBlock>
                                    </FilterTemplate>
</telerik:GridBoundColumn>

5 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 02 Apr 2015, 08:27 AM
Hello,

The problem may be caused by the fact that the logic is executed inside the OnItemCreated event. Please try moving it inside the OnItemDataBound one and test the page again.

If this does not prove helpful please share with us the entire page contents(markup and code-behind) so we could examine the setup.

Regards,
Angel Petrov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Sergey
Top achievements
Rank 1
answered on 03 Apr 2015, 02:51 PM

Most probably you are right. The problem maybe caused by the fact that it is in OnItemCreated handler. But i cannot put it into OnItemDataBound event because it is happening only once and i need to fill second combobox on postback based on selected value in first combobox.

 It is fired on postback only for GridHeaderItem.

In case i set EnableViewState='false' for the grid - it does fires for GridFilteringItem. It even doesn't throw exception on C# side, but on client side it does throw it. (see in the attachments)

0
Sergey
Top achievements
Rank 1
answered on 03 Apr 2015, 03:34 PM

Here you can find the sample 

https://drive.google.com/file/d/0B1n1I_naPpYmWDJOQkNuWVZEWU0/view?usp=sharing

0
Sergey
Top achievements
Rank 1
answered on 03 Apr 2015, 03:37 PM
Sorry, correct link - Link
0
Angel Petrov
Telerik team
answered on 08 Apr 2015, 12:39 PM
Hello,

Attached you can find a modified version of the provided solution that illustrates how one can safely relate the drop downs. Please examine its implementation and give the illustrated approach a try.

Regards,
Angel Petrov
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Sergey
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Sergey
Top achievements
Rank 1
Share this question
or