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

Grid updated by ajaxmanager loses selected row

1 Answer 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Laura
Top achievements
Rank 1
Laura asked on 24 Dec 2008, 10:45 PM
I have a page with 2 grids on it.When you select a row on the first grid, a second grid related to the row is created. I use javascript to select the row and then call the radajaxmanager to rebind the second grid. I also have an insert button on the first grid. I have the radajaxmanager updating both grids. When I have the ajaxmanager updating both grids, the selected row does not remain highlighted. If I remove from the ajax manager, then after inserting a new record in the first grid, it does not rebind to show the new record. Here is my code:

function rowSelected(sender, eventArgs) { 
            var dataItem = $get(eventArgs.get_id()); 
            var grid = sender
            var MasterTable = grid.get_masterTableView(); 
            var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()]; 
            var id = MasterTable.getCellByColumnUniqueName(row, "package_id").innerHTML; 
            var description = MasterTable.getCellByColumnUniqueName(row, "descriptions").innerHTML; 
 
 
            var packageIDtxtbox = document.getElementById("packageID"); 
            packageIDtxtbox.value = id
 
            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("PackageContents"); 
        } 
         
        function EditPackageContents() { 
            var packageIDtxtbox = document.getElementById("packageID"); 
            if (packageIDtxtbox != null) { 
                var pID = packageIDtxtbox.value; 
                var oWnd = window.radopen("entitlements.aspx?pID=" + pID +"&price=Y", "entitlements"); 
                oWnd.add_close(OnClientCloseEditContents); 
                var oArg = new Object(); 
 
                 
 
                //set the arguments that will be needed on the way back so they are not undefined 
                oWnd.argument = oArg
                return false; 
            } 
            return false; 
        } 
        function OnClientCloseEditContents(oWnd) { 
            // rebind the buildPackageGrid 
                $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("PackageContents"); 
            } 
        function GetRadWindow() { 
             var oWindow = null
             if (window.radWindow) oWindow = window.radWindow; 
             else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; 
             return oWindow; 
         } 
 
 
         function ShowInsertForm() { 
 
             var oWnd = window.radopen("editPackageForm.aspx", "packageDialog"); 
             oWnd.setSize(800, 300); 
             oWnd.center(); 
 
             //set a function to be called when RadWindow is closed 
             oWnd.add_close(OnClientCloseEdit); 
             var oArg = new Object(); 
 
             oArg.packageID = -99; 
 
             //set the arguments that will be needed on the way back so they are not undefined 
             oWnd.argument = oArg
             return false; 
         } 
         function ShowEditForm(id, rowIndex) { 
             var grid = $find("<%= packageGrid.ClientID %>"); 
 
             var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element(); 
             grid.get_masterTableView().selectItem(rowControl, true); 
 
             var oWnd = window.radopen("editPackageForm.aspx?packageID=" + id, "packageDialog"); 
             oWnd.setSize(800, 300); 
             oWnd.center(); 
              
             oWnd.add_close(OnClientCloseEdit); 
             var oArg = new Object(); 
 
             oArg.packageID = id
 
             //set the arguments that will be needed on the way back so they are not undefined 
             oWnd.argument = oArg
             return false; 
         } 
         
         function OnClientCloseEdit(oWnd) { 
             //get the transferred arguments 
             var packageID = oWnd.argument.packageID; 
             if (packageID != -99) { 
                 // rebind grid 
                 var txtBoxPackageID = document.getElementById("packageID"); 
                 txtBoxPackageID.value = packageID
                 $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("PackageEdit"); 
             } 
 
 
         } 
             
 </script> 
    
   </telerik:RadScriptBlock>     
  
  
     <div> 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"  
            onajaxrequest="RadAjaxManager1_AjaxRequest"  
            DefaultLoadingPanelID="RadAjaxLoadingPanel1"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"
                        <UpdatedControls> 
                            <telerik:AjaxUpdatedControl ControlID="packageGrid" /> 
                            <telerik:AjaxUpdatedControl ControlID="outdatedPackageGrid" /> 
                            <telerik:AjaxUpdatedControl ControlID="buildPackageGrid" /> 
                        </UpdatedControls> 
                 </telerik:AjaxSetting> 
                <telerik:AjaxSetting AjaxControlID="packageID"
                </telerik:AjaxSetting> 
                <telerik:AjaxSetting AjaxControlID="mainSplitter"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="mainSplitter" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
               
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
         
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Height="75px" Width="75px" Transparency="10"
        <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' 
            style="border: 0px;" /> 
        </telerik:RadAjaxLoadingPanel> 
   
        
        <telerik:RadSplitter ID"mainSplitter" runat="server" Orientation="Vertical"  ResizeMode="AdjacentPane" width="100%"  
                VisibleDuringInit="false" Height="100%" ResizeWithParentPane="true"
         <telerik:RadPane id="leftPane" runat="server"    width="22"   minwidth="22" Scrolling="none"
           <telerik:RadSlidingZone id="SlidingZone1" runat="server"   clicktoopen="true"  DockedPaneId="sPackages" ExpandedPaneId="sPackages" > 
            <telerik:RadSlidingPane id="sPackages" title="Packages" runat="server" width="215"   Scrolling="Both" EnableResize="false" > 
              <telerik:RadGrid ID="packageGrid" runat="server"  Width="200px"  OnItemDataBound="RadGrid1_ItemDataBound" 
                    DataSourceID="SqlDataSourcePackages" AutoGenerateColumns="False"  OnItemCreated="packagesGrid_ItemCreated" 
                    GridLines="None" AllowFilteringByColumn="True" AllowPaging="True" > 
                  <GroupingSettings CaseSensitive="false" /> 
                  <ClientSettings> 
                   <Selecting AllowRowSelect="true"  EnableDragToSelectRows="true" /> 
                   <ClientEvents  OnRowSelected="rowSelected" /> 
                  </ClientSettings>    
                
                   
                  <HeaderContextMenu EnableTheming="True"
                      <CollapseAnimation Duration="200" Type="OutQuint" /> 
                  </HeaderContextMenu> 
                  <MasterTableView CommandItemDisplay="Top" DataKeyNames="package_id" PageSize="25"
                      <RowIndicatorColumn> 
                          <HeaderStyle Width="20px" /> 
                      </RowIndicatorColumn> 
                      <ExpandCollapseColumn> 
                          <HeaderStyle Width="20px" /> 
                      </ExpandCollapseColumn> 
                      <CommandItemTemplate > 
                        <div style="padding:10px 5px;"
                         <asp:LinkButton  runat="server" id="addButton" OnClientClick="return ShowInsertForm(); return false;" > 
                         <img style="border:0px;vertical-align:middle;" alt="" src="Images/AddRecord.gif" />Add new package</asp:LinkButton> 
                 
                           &nbsp;&nbsp;&nbsp;&nbsp; 
                                            
                       </div> 
                      </CommandItemTemplate> 
                      <CommandItemSettings AddNewRecordText="Add new package"  /> 
                      <Columns> 
                      <telerik:GridTemplateColumn AllowFiltering="false" > 
           <HeaderStyle Width="20px" /> 
            <ItemTemplate> 
              <asp:imagebutton ID="EditPackageLink" runat="server" Text="Edit Package" src="Images/Edit.gif" ToolTip="Edit"></asp:imagebutton> 
            </ItemTemplate> 
           </telerik:GridTemplateColumn> 
                          <telerik:GridBoundColumn DataField="package_id" Display="false"  
                              UniqueName="package_id"
                          </telerik:GridBoundColumn> 
                          <telerik:GridTemplateColumn UniqueName="packageName" HeaderText="Package Name" > 
                           <ItemTemplate> 
                            <asp:Label ID="package_name" runat="server" Text='<%#Eval("package_name") %>'></asp:Label> 
                            <telerik:RadToolTip runat="server" ID="RadToolTip2" TargetControlID="package_name"  
                                Skin="Web20" ShowDelay="1000" AutoCloseDelay="200000" Font-Names="arial"  
                                Font-Size="XX-Large" BorderStyle="Inset" HideDelay="100000" ManualClose="False"  
                                Position="BottomRight" Sticky="True" Width="300"><asp:Label runat="server" ID="Label111"  Font-Bold="true" TabIndex="2" Text='<%#Eval("descriptions") %>' ></asp:Label><br/>  
                            </telerik:RadToolTip> 
                           </ItemTemplate> 
                          </telerik:GridTemplateColumn> 
                           
                          <telerik:GridBoundColumn DataField="descriptions" Display="false"  
                              UniqueName="descriptions"
                          </telerik:GridBoundColumn> 
                          <telerik:GridBoundColumn DataField="do_not_delete" Display="false"  
                              UniqueName="do_not_delete"
                          </telerik:GridBoundColumn> 
                          <telerik:GridDateTimeColumn DataField="start_date" Display="false" UniqueName="start_date"></telerik:GridDateTimeColumn> 
                          <telerik:GridDateTimeColumn DataField="end_date"  Display="false" UniqueName="end_date"></telerik:GridDateTimeColumn> 
                          <telerik:GridBoundColumn DataField="active" Display="false" UniqueName="active"></telerik:GridBoundColumn> 
                          <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"  
                              ConfirmDialogType="RadWindow" ConfirmText="Delete this package?"  
                              ConfirmTitle="Delete" Text="Delete" UniqueName="DeleteCol"
                          </telerik:GridButtonColumn> 
                      </Columns> 
                  </MasterTableView> 
                  <FilterMenu EnableTheming="True"
                      <CollapseAnimation Duration="200" Type="OutQuint" /> 
                  </FilterMenu> 
              </telerik:RadGrid> 
              <br /><br /> 
              <asp:Label runat="server" Text="Show outdated packages" AssociatedControlID="outdatedCB" ></asp:Label><asp:CheckBox runat="server" ID="outdatedCB" OnCheckedChanged="outdatedChanged" AutoPostBack="true" /> 
              <telerik:RadGrid ID="outdatedPackageGrid" runat="server"  Width="200px"  OnItemDataBound="RadGrid1_ItemDataBound" 
                    DataSourceID="SqlDataSourceOutdatedPackages" AutoGenerateColumns="False"  OnItemCreated="packagesGrid_ItemCreated" 
                    GridLines="None" AllowFilteringByColumn="True" AllowPaging="True" Visible="false" > 
                  <GroupingSettings CaseSensitive="false" /> 
                  <ClientSettings> 
                   <Selecting AllowRowSelect="true"  EnableDragToSelectRows="true" /> 
                   <ClientEvents  OnRowSelected="rowSelectedOutdated" /> 
                  </ClientSettings> 
                
                   
                  <HeaderContextMenu EnableTheming="True"
                      <CollapseAnimation Duration="200" Type="OutQuint" /> 
                  </HeaderContextMenu> 
                  <MasterTableView CommandItemDisplay="Top" DataKeyNames="package_id"
                      <RowIndicatorColumn> 
                          <HeaderStyle Width="20px" /> 
                      </RowIndicatorColumn> 
                      <ExpandCollapseColumn> 
                          <HeaderStyle Width="20px" /> 
                      </ExpandCollapseColumn> 
                      <CommandItemTemplate > 
                        <div style="padding:10px 5px;"
                        Outdated Packages 
                 
                           &nbsp;&nbsp;&nbsp;&nbsp; 
                                            
                       </div> 
                      </CommandItemTemplate> 
                      <CommandItemSettings AddNewRecordText="Add new package"  /> 
                      <Columns> 
                      <telerik:GridTemplateColumn AllowFiltering="false" > 
           <HeaderStyle Width="20px" /> 
            <ItemTemplate> 
              <asp:imagebutton ID="EditPackageLink" runat="server" Text="Edit Package" src="Images/Edit.gif" ToolTip="Edit"></asp:imagebutton> 
            </ItemTemplate> 
           </telerik:GridTemplateColumn> 
                          <telerik:GridBoundColumn DataField="package_id" Display="false"  
                              UniqueName="package_id"
                          </telerik:GridBoundColumn> 
                          <telerik:GridTemplateColumn UniqueName="packageName" HeaderText="Package Name" > 
                           <ItemTemplate> 
                            <asp:Label runat="server" ID="package_name" Text='<%#Eval("package_name") %>'></asp:Label> 
                            <telerik:RadToolTip runat="server" ID="RadToolTip2" TargetControlID="package_name"  
                                Skin="Web20" ShowDelay="1000" AutoCloseDelay="200000" Font-Names="arial"  
                                Font-Size="XX-Large" BorderStyle="Inset" HideDelay="100000" ManualClose="False"  
                                Position="BottomRight" Sticky="True" Width="300"><asp:Label runat="server" ID="Label111"  Font-Bold="true" TabIndex="2" Text='<%#Eval("descriptions") %>' ></asp:Label><br/>  
                            </telerik:RadToolTip> 
                           </ItemTemplate> 
                          </telerik:GridTemplateColumn> 
                           
                          <telerik:GridBoundColumn DataField="descriptions" Display="false"  
                              UniqueName="descriptions"
                          </telerik:GridBoundColumn> 
                          <telerik:GridBoundColumn DataField="do_not_delete" Display="false"  
                              UniqueName="do_not_delete"
                          </telerik:GridBoundColumn> 
                          <telerik:GridDateTimeColumn DataField="start_date" Display="false" UniqueName="start_date"></telerik:GridDateTimeColumn> 
                          <telerik:GridDateTimeColumn DataField="end_date"  Display="false" UniqueName="end_date"></telerik:GridDateTimeColumn> 
                          <telerik:GridBoundColumn DataField="active" Display="false" UniqueName="active"></telerik:GridBoundColumn> 
                          <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"  
                              ConfirmDialogType="RadWindow" ConfirmText="Delete this package?"  
                              ConfirmTitle="Delete" Text="Delete" UniqueName="DeleteCol"
                          </telerik:GridButtonColumn> 
                      </Columns> 
                  </MasterTableView> 
                  <FilterMenu EnableTheming="True"
                      <CollapseAnimation Duration="200" Type="OutQuint" /> 
                  </FilterMenu> 
              </telerik:RadGrid> 
               
               
            </telerik:RadSlidingPane> 
           </telerik:RadSlidingZone> 
          </telerik:RadPane> 
          <telerik:RadSplitBar id="Radsplitbar3" runat="server" collapsemode="Forward"   /> 
          <telerik:RadPane id="contentPane" runat="server"  Scrolling="Y"    >  
           <telerik:RadAjaxPanel ID="Panel1" runat="server" BackColor="White">  
           <div id="PackageForm" runat="server" > 
             
           <table runat="server" id="totalBar" > 
            <tr> 
            <td  colspan="3"
                 
                <table cellpadding="0" cellspacing="0" class="style15" > 
                    <tr> 
                        <td> 
                            &nbsp;</td><td
                            &nbsp;</td><td
                            &nbsp;</td><td
                            &nbsp;</td><td
                            &nbsp;</td><td
                            &nbsp;</td></tr></table></td></tr><tr
                         
                    <td class="style13"
                        &nbsp;</td><td class="style14"
                    </td> 
                    <td class="style13"
                    </td> 
                         
                    </tr> 
                    <tr> 
                        <td class="style2"
                            </td> 
                        <td class="style3" colspan="2"
                            <telerik:RadGrid ID="buildPackageGrid" runat="server" visible="false" 
                                AllowFilteringByColumn="True" AllowPaging="True"  
                                DataSourceID="SqlDataSourceselectPackage" GridLines="None"  OnDataBound="buildPackageGrid_dataBound" 
                                OnItemDataBound="build_ItemDataBound" OnPreRender="buildPackageGrid_preRender"  
                                Width="633px"
                                <HeaderContextMenu EnableTheming="True"
                                    <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                </HeaderContextMenu> 
                                <GroupingSettings CaseSensitive="false" /> 
                                <MasterTableView runat="server" AutoGenerateColumns="False" CommandItemDisplay="Top" 
                                    DataKeyNames="mid_id,mid_type_id" PageSize="12"
                                    <GroupByExpressions> 
                                        <telerik:GridGroupByExpression> 
                                            <GroupByFields> 
                                                <telerik:GridGroupByField FieldName="mid_type_name" SortOrder="Descending" /> 
                                            </GroupByFields> 
                                            <SelectFields> 
                                                <telerik:GridGroupByField FieldAlias="mid_type_name" FieldName="mid_type_name"  
                                                    HeaderText="Mid type" /> 
                                            </SelectFields> 
                                        </telerik:GridGroupByExpression> 
                                    </GroupByExpressions> 
                                    <RowIndicatorColumn> 
                                        <HeaderStyle Width="20px" /> 
                                    </RowIndicatorColumn> 
                                    <ExpandCollapseColumn> 
                                        <HeaderStyle Width="20px" /> 
                                    </ExpandCollapseColumn> 
                                    <CommandItemTemplate > 
                        <div style="padding:10px 5px;"
                         <asp:LinkButton  runat="server" id="editButton" OnClientClick="return EditPackageContents(); return false;" > 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <img style="border:0px;vertical-align:middle;" alt="" src="Images/Edit.gif" />Edit package contents</asp:LinkButton>&nbsp;&nbsp;&nbsp;&nbsp; 
                                            
                       </div> 
                      </CommandItemTemplate> 
                      <CommandItemSettings AddNewRecordText="Edit package contents"  /> 
                                    <Columns> 
                                        <telerik:GridBoundColumn DataField="mid_id" Display="false" UniqueName="mid_id"
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="mid_type_id" Display="false"  
                                            UniqueName="mid_type_id"
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="mid_name" HeaderText="Package Contents"  
                                            UniqueName="mid_name"
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridBoundColumn DataField="package_name" Display="false"  
                                            HeaderText="Package Name" SortExpression="package_name"  
                                            UniqueName="package_name"
                                        </telerik:GridBoundColumn> 
                                        <custom:MyCustomFilteringColumnMidTypes DataField="mid_type_name" HeaderText="Mid Types"
                                         <headerstyle width="100px" /> 
                                            <itemtemplate> 
                                                <%# Eval("mid_type_name")%> 
                                            </itemtemplate> 
                                         </custom:MyCustomFilteringColumnMidTypes> 
                                        <telerik:GridBoundColumn DataField="mid_type_name" HeaderText="Mid type"  
                                            SortExpression="mid_type_name" UniqueName="mid_type_name"
                                        </telerik:GridBoundColumn> 
                                        <telerik:GridNumericColumn DataField="price" UniqueName="price"  ></telerik:GridNumericColumn> 
                                        <telerik:GridNumericColumn DataField="asking_price" UniqueName="asking_price"  ></telerik:GridNumericColumn> 
                                    </Columns> 
                                    <PagerStyle Mode="NextPrevAndNumeric" /> 
                                </MasterTableView> 
                                <FilterMenu EnableTheming="True"
                                    <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                </FilterMenu> 
                            </telerik:RadGrid> 
                        </td> 
                        <td> 
                            &nbsp;</td></tr><tr> 
                        <td class="style2"
                            &nbsp;</td><td class="style3"
                            &nbsp;</td><td class="style1"
                            &nbsp;</td></tr></table></div></telerik:RadAjaxPanel></telerik:RadPane></telerik:RadSplitter><asp:TextBox ID="packageID" runat="server" Visible="true" Width="0" Height="0" 
             style="border: 0px solid #b0c4de;background-color:#b0c4de;"></asp:TextBox><asp:TextBox ID="packageName" runat="server" Visible="true" Width="0" Height="0" 
             style="border: 0px solid #b0c4de;background-color:#b0c4de;"></asp:TextBox><telerik:RadNumericTextBox ID="totalPackagePrice" runat="server" Value="0"  ></telerik:RadNumericTextBox> 
       <telerik:RadNumericTextBox ID="totalOurCost" runat="server" Value="0"  ></telerik:RadNumericTextBox> 
         <asp:SqlDataSource ID="SqlDataSourcePackages" runat="server"  
            ConnectionString="<%$ ConnectionStrings:CC2ConnectionString2 %>"  
             
              
              
             SelectCommand="SELECT package_id, package_name, package_cd, mid_id, descriptions, last_changed_by, date_created, date_last_changed, do_not_delete, start_date, end_date, active FROM PACKAGES WHERE (end_date IS NULL) OR (end_date &gt;= GETDATE())"></asp:SqlDataSource>     
         <asp:SqlDataSource ID="SqlDataSourceOutdatedPackages" runat="server"  
            ConnectionString="<%$ ConnectionStrings:CC2ConnectionString2 %>"  


 protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) 
        { 
            if ("PackageEdit" == e.Argument) 
            { 
                packageGrid.Rebind(); 
                if (outdatedPackageGrid.Visible == true
                    outdatedPackageGrid.Rebind(); 
            } 
            else if ("PackageContents" == e.Argument) 
            { 
                buildPackageGrid.Visible = true
                buildPackageGrid.Rebind(); 
            } 
        } 

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 29 Dec 2008, 12:36 PM
Hello Laura,

One possible solution in this case would be to manually persist the selection for the control in question.
The following article contains more information on one possible approach.

Sincerely yours,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Laura
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or