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

RadComboBox in PagerTemplate

1 Answer 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Calvin
Top achievements
Rank 1
Calvin asked on 25 Nov 2008, 07:36 PM
I have a RadComboBox is inside a PagerTemplate within a grid.  Sometimes OnSelectedIndexchanged is called with the incorrect sender and incorrect new value.  ie if i change the combobox on the top the bottom one is passed in.   In the case of the aspx i have below OnSelectedIndexchanged is called with the wrong values.

In particular when combbox is set to the default value(value that it gets set to when first visiting the page) the wrong value is passed in.

Thanks in advance,
Calvin

ps. Below is the a snippet of what i have in the aspx page and the method called when the index is changed:

<telerik:RadGrid ID="RadGrid1"  runat="server"
            Skin="Office2007"
            AllowPaging="True"
            AllowCustomSorting="true"
            PagerStyle-AlwaysVisible="true"
            AllowSorting="True"
            GridLines="None"  
            AutoGenerateColumns="false"
            OnNeedDataSource="RadGid1_NeedDataSource"
            OnItemDataBound="RadGrid1_ItemDataBound"
            OnItemCommand="RadGrid1_ItemCommand"
            OnItemCreated="RadGrid1_ItemCreated"
            OnColumnCreated="RadGrid1_ColumnCreated"
            ShowStatusBar="false"
            ShowHeader="false"
            ClientSettings-Resizing-AllowColumnResize="true"
            >

    <MasterTableView  GroupLoadMode="Client"  >
        <GroupByExpressions>
                    <telerik:GridGroupByExpression>
                        <SelectFields>
                            <telerik:GridGroupByField  HeaderText="&nbsp;&nbsp;&nbsp;&nbsp;" HeaderValueSeparator="" FieldAlias="Events" FieldName="Day" FormatString="{0:dddd, MMMM d, yyyy}"></telerik:GridGroupByField>
                        </SelectFields>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldName="Day" SortOrder="Ascending"></telerik:GridGroupByField>
                        </GroupByFields>
                    </telerik:GridGroupByExpression>
                </GroupByExpressions>
        <Columns>
            <telerik:GridEditCommandColumn UniqueName="viewDetails" ButtonType="ImageButton"  EditImageUrl="../Images/plus.png">
            </telerik:GridEditCommandColumn>
            <telerik:GridTemplateColumn UniqueName="SingleColumn">
                <ItemTemplate>
                    <!-- Items -->                      
                    </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
                <EditFormSettings EditFormType="Template">
                    <FormTemplate>
                        <CHO:TemplateViewer id="templateViewer" runat="server" MiniTemplate="true" />
                    </FormTemplate>
                </EditFormSettings>
                <PagerTemplate>
                    <asp:Panel ID="PagerPanel" Style="padding: 6px;" runat="server">
                    <telerik:RadComboBox id="cbSort" runat="server"  AutoPostBack="true" OnSelectedIndexChanged="cbSort_OnIndexChanged" EnableViewState="true">
                        <Items>
                            <telerik:RadComboBoxItem Text="Event Date" Value="Day" />
                            <telerik:RadComboBoxItem Text="Event Name" Value="EventName" />
                            <telerik:RadComboBoxItem Text="Category" Value="CategoryName" />
                        </Items>
                    </telerik:RadComboBox>                            
                        <div class="listPageNumber">                        
                            <asp:Panel runat="server" ID="NumericPagerPlaceHolder" >  </asp:Panel>
                        </div>
                        <div class="listPageSize">                            
                            <span class="listPageSizeText">Page size:</span>
                            <telerik:RadComboBox ID="cbPaging" DataSource="<%# new object[]{10, 20, 30, 40, 50} %>"
                                Skin="Office2007" SelectedValue='<%# DataBinder.Eval(Container, "Paging.PageSize") %>'
                                runat="server" OnClientSelectedIndexChanged="RadComboBox1_SelectedIndexChanged">
                            </telerik:RadComboBox>
                        </div>
                    </asp:Panel>
                </PagerTemplate>
                <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" Position="TopAndBottom" ShowPagerText="false"   ></PagerStyle>
               </MasterTableView>
        </telerik:RadGrid>

-------------------------- code behind----------------

protected void cbSort_OnIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            RadGrid1.MasterTableView.GroupByExpressions.Clear();
            RadGrid1.MasterTableView.SortExpressions.Clear();
            
            var group = new GridGroupByExpression();
            var field = new GridGroupByField();

            switch (e.Value)
            {
                case DayFieldName:
                   /*set sorting and grouping*/
                    break;
                case CategoryFieldName:
                   /*set sorting and grouping*/
                    break;
                case EventFieldName:
                   /*set sorting and grouping*/
                    break;
                default:
                   /*set sorting and grouping*/
                    break;
            }
            RadGrid1.MasterTableView.Rebind();

            //Selects the correct item in the combo box based on the new value
            ((RadComboBox) RadGrid1.MasterTableView.GetItems(GridItemType.Pager)[0].FindControl("cbSort")).SelectedValue
                = e.Value;
            ((RadComboBox)RadGrid1.MasterTableView.GetItems(GridItemType.Pager)[1].FindControl("cbSort")).SelectedValue
                = e.Value;
        }

1 Answer, 1 is accepted

Sort by
0
Calvin
Top achievements
Rank 1
answered on 25 Nov 2008, 09:02 PM
I found the problem.  This was occurring because of our attempt to use viewstate compression.  Once it has been turned off it works fine.
Tags
Grid
Asked by
Calvin
Top achievements
Rank 1
Answers by
Calvin
Top achievements
Rank 1
Share this question
or