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

Radgrid sorting not working when dynamically loading it inside a usercontrol.

3 Answers 63 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ravi
Top achievements
Rank 1
Ravi asked on 22 Sep 2011, 05:19 AM
I have a grid named gvTabList which in inside the usercontrol . I load this usercontrol at runtime from Default.aspx when an image button is clicked.

<telerik:RadAjaxManager ID="radAjaxManagerTab" runat="server">
                               <AjaxSettings>
                                   <telerik:AjaxSetting AjaxControlID="gvTabList">
                                       <UpdatedControls>
                                           <telerik:AjaxUpdatedControl ControlID="gvTabList" LoadingPanelID="ajaxLoadingPanel"  />
                                                                             
                                       </UpdatedControls>
                                   </telerik:AjaxSetting>
                               </AjaxSettings>
                           </telerik:RadAjaxManager>
                            <telerik:RadAjaxLoadingPanel ID="ajaxLoadingPanel" runat="server" IsSticky="true"
                       Skin="Default" Style="position: absolute; z-index: 101; top: 0; left: 0;">
                       <img alt="Loading" src="../Images/Loading.gif" />
                   </telerik:RadAjaxLoadingPanel>
                           <telerik:RadGrid ID="gvTabList" runat="server" Skin="WebBlue" AllowFilteringByColumn="True"
                               AllowPaging="True" PageSize="5" AllowSorting="True"
                                OnNeedDataSource="gvTabList_NeedDataSource"
                                OnInit="gvTabList_Init"
                                AutoGenerateColumns="False" GridLines="None" OnSortCommand="gvTabList_SortCommand" EnableAJAX="True" >                             
                               <GroupingSettings CaseSensitive="false" />
                               <MasterTableView AllowFilteringByColumn="true" AllowMultiColumnSorting="false" AllowCustomSorting="true">
                                   <RowIndicatorColumn Visible="False">
                                       <HeaderStyle Width="20px"></HeaderStyle>
                                   </RowIndicatorColumn>
                                   <ExpandCollapseColumn Visible="False">
                                       <HeaderStyle Width="19px"></HeaderStyle>
                                   </ExpandCollapseColumn>
                                   <CommandItemSettings ExportToPdfText="Export to Pdf" />
                                   <Columns>
                                       <telerik:GridBoundColumn AllowFiltering="False" DataField="ID" HeaderText="HEDIS #"
                                           UniqueName="HedisID">
                                           <HeaderStyle HorizontalAlign="Center" Width="140" />
                                           <ItemStyle HorizontalAlign="Center" />
                                       </telerik:GridBoundColumn>
                                       <telerik:GridBoundColumn AllowFiltering="False" DataField="HedisSubMeasure" HeaderText="HEDIS Domain"
                                           UniqueName="HedisDomain">
                                           <HeaderStyle HorizontalAlign="Center" Width="150" />
                                           <ItemStyle HorizontalAlign="Center" />
                                       </telerik:GridBoundColumn>
                                          
                                   </Columns>
                               </MasterTableView>
                                <PagerStyle Mode="NumericPages" />
                           </telerik:RadGrid>


I need to display this control when the user clicks the image button that is why I have kept it inside btnLoadControl_Click event. But there are so many forums saying controls have to be loaded either during Page_Load or Init method. I am not sure how to do that.

protected void btnLoadControl_Click(object sender, ImageClickEventArgs e)
       {
             UserControl control = (UserControl)LoadControl("~/Controls/" + Usercontrolname + ".ascx");
 
       }


There is no problem loading the usercontrol when the condition is met. But the problem is when I click the heading of any column, the sortorder does not change. I have my funtion to handle the CustomSorting which is given below.

protected void gvTabList_SortCommand(object source, GridSortCommandEventArgs e)
       {          
            GridSortExpression sortExpr = new GridSortExpression();          
           switch (e.OldSortOrder)           
           {
               case GridSortOrder.None:
                   sortExpr.FieldName = e.SortExpression;
                   sortExpr.SortOrder = GridSortOrder.Descending;
                   e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);                   
                   break;
               case GridSortOrder.Ascending:
                   sortExpr.FieldName = "ID";
                   sortExpr.SortOrder = GridSortOrder.Ascending;
                   e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
                     
                   break;
               case GridSortOrder.Descending:
                   sortExpr.FieldName = e.SortExpression;
                   sortExpr.SortOrder = GridSortOrder.Ascending;
                   e.Item.OwnerTableView.SortExpressions.AddSortExpression(sortExpr);
                    
                   break;
           }
           e.Canceled = true;    
           gvTabList.Rebind();
  
       }

I checked by debugging, but " e.OldSortOrder" always gives "None" type.
Is this problem related with dynamically loading the usercontrol . As you can see I need this usercontrol only when the Image button is clicked. so I am not loading it in Init method.
If any one has faced this problem, please send me the solution. It will be a great help.












3 Answers, 1 is accepted

Sort by
0
Cabot
Top achievements
Rank 1
answered on 06 Sep 2012, 03:41 PM
I am also having this problem with the latest release of the RadGrid control
0
Marin
Telerik team
answered on 11 Sep 2012, 12:27 PM
Hi,

 If you dynamically load a user control make sure that this is done in the Init or Load event of the page. This way the viewstate of the grid will managed properly and all the features should work as expected. Additionally about ajaxifying dynamically loaded user controls you can have a look at this help topic.

Kind regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
RB
Top achievements
Rank 1
answered on 28 Jul 2014, 08:59 PM
Were you able to resolve this? I have the same problem!
Tags
Grid
Asked by
Ravi
Top achievements
Rank 1
Answers by
Cabot
Top achievements
Rank 1
Marin
Telerik team
RB
Top achievements
Rank 1
Share this question
or