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

Loose ability to select rows after calling Rebind()

7 Answers 110 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan Dailey
Top achievements
Rank 1
Ryan Dailey asked on 02 Aug 2010, 04:54 PM
I currently am trying to perform a rebind of the Grid through AJAX whenever a node on a RadTreeView control is clicked.  The new data is successfully rebound, but for some reason the ability after rebinding I loose the ability to select items inside the grid.

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <ClientEvents />
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="rtFiles" EventName="OnNodeClick">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="grdFiles" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
  
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadSplitter ID="Splitter" Width="100%" runat="server">
    <telerik:RadPane ID="Pane1" runat="server">
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
        <telerik:RadTreeView ID="rtFiles" runat="server"
            EnableAjaxSkinRendering="true"
            AllowNodeEditing="false"
            OnClientContextMenuItemClicking="rtFiles_onClientContextMenuItemClicking"
            oncontextmenuitemclick="rtFiles_ContextMenuItemClick" 
            onnodeedit="rtFiles_NodeEdit"
            OnNodeClick="rtFiles_NodeClick"
            >
            <ContextMenus>
                <telerik:RadTreeViewContextMenu ID="fileContextMenu">
                    <Items>
                        <telerik:RadMenuItem Text="Rename" Value="rename" PostBack="false"></telerik:RadMenuItem>
                        <telerik:RadMenuItem Text="Delete" Value="delete"></telerik:RadMenuItem>
                    </Items>
                </telerik:RadTreeViewContextMenu>
                <telerik:RadTreeViewContextMenu ID="albumContextMenu">
                    <Items>
                        <telerik:RadMenuItem Text="New Album" Value="newAlbum"></telerik:RadMenuItem>
                        <telerik:RadMenuItem Text="Upload File" Value="uploadFile"></telerik:RadMenuItem>
                        <telerik:RadMenuItem Text="Rename" Value="rename" PostBack="false"></telerik:RadMenuItem>
                        <telerik:RadMenuItem Text="Delete" Value="delete"></telerik:RadMenuItem>
                    </Items>
                </telerik:RadTreeViewContextMenu>
            </ContextMenus>
        </telerik:RadTreeView>
    </telerik:RadPane>
    <telerik:RadSplitBar ID="Split1" CollapseMode="Backward" runat="server" />
    <telerik:RadPane ID="Pane2" runat="server">
        <telerik:RadGrid ID="grdFiles" Width="100%" runat="server" AllowMultiRowSelection="true"
            onneeddatasource="grdFiles_NeedDataSource" 
            OnItemDataBound="grdFiles_ItemDataBound" >
            <SelectedItemStyle BackColor="Red" />
            <MasterTableView ShowHeader="true" UseAllDataFields="false" AutoGenerateColumns="false" RetrieveAllDataFields="false">
                <Columns>
                    <telerik:GridTemplateColumn HeaderText="File Name" >
                        <HeaderStyle Width="20px" />
                        <ItemTemplate>
                            <img src="/internetsite/Images/Icons/<%# Convert.ToBoolean(Convert.ToString(DataBinder.Eval(Container.DataItem, "Title")).Contains("."))? Convert.ToString(DataBinder.Eval(Container.DataItem, "Title")).Substring(Convert.ToString(DataBinder.Eval(Container.DataItem, "Title")).LastIndexOf(".") + 1) + ".gif" : "folder.gif" %>" /> <%# DataBinder.Eval(Container.DataItem, "Title") %>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings EnableRowHoverStyle="true">
                <Selecting AllowRowSelect="true" />
            </ClientSettings>
        </telerik:RadGrid>
    </telerik:RadPane>
</telerik:RadSplitter>

protected void grdFiles_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
   {
       string strValue;
       if (rtFiles.SelectedNode == null)
       {
           strValue = rtFiles.Nodes[0].Value;
       }
       else
       {
           strValue = rtFiles.SelectedNode.Value;
       }
       reloadDataSource_grdFiles(int.Parse(strValue.Substring(strValue.IndexOf("_") + 1)));
   }
protected void reloadDataSource_grdFiles(int intId)
   {
       grdFiles.MasterTableView.DataKeyNames = new string[] { "Id", "Title" };
       grdFiles.DataSource = myDataSource(intID);
   }

7 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 05 Aug 2010, 01:37 PM
Hello Ryan,

It is hard to say what is causing the unwanted behavior without having the running application and reproduce the issue. Could you please send us a simple runnable example which demonstrating the unwanted behavior. You could open a formal support ticket from your Telerik account and attach a ZIP file there. Thus we will be able to review the issue locally and provide a solution.

All the best,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ryan Dailey
Top achievements
Rank 1
answered on 05 Aug 2010, 06:58 PM
Hello Pavlina,
I am running this control under Sitefinity 3.7.

Try this.  This is the full code for the user control.  I bound it to a simple array of objects instead of a datasource.  And I do still get the same problem.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TreeAndGrid.ascx.cs" Inherits="UserControls_TreeAndGrid" %>
<script type="text/javascript" language="javascript">
</script>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <ClientEvents />
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="rtFiles" EventName="OnNodeClick">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="grdFiles" LoadingPanelID="RadAjaXLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="ViewState" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
  
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadSplitter ID="fileExSplitter" Width="100%" runat="server">
    <telerik:RadPane ID="fileExPane1" runat="server">
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
        <telerik:RadTreeView ID="rtFiles" runat="server"
            EnableAjaxSkinRendering="true"
            AllowNodeEditing="false"
            OnNodeClick="rtFiles_NodeClick">
            <ContextMenus>
                <telerik:RadTreeViewContextMenu ID="fileContextMenu">
                    <Items>
                        <telerik:RadMenuItem Text="Rename" Value="rename" PostBack="false"></telerik:RadMenuItem>
                        <telerik:RadMenuItem Text="Delete" Value="delete"></telerik:RadMenuItem>
                    </Items>
                </telerik:RadTreeViewContextMenu>
                <telerik:RadTreeViewContextMenu ID="albumContextMenu">
                    <Items>
                        <telerik:RadMenuItem Text="New Album" Value="newAlbum"></telerik:RadMenuItem>
                        <telerik:RadMenuItem Text="Upload File" Value="uploadFile"></telerik:RadMenuItem>
                        <telerik:RadMenuItem Text="Rename" Value="rename" PostBack="false"></telerik:RadMenuItem>
                        <telerik:RadMenuItem Text="Delete" Value="delete"></telerik:RadMenuItem>
                    </Items>
                </telerik:RadTreeViewContextMenu>
            </ContextMenus>
            <Nodes>
                <telerik:RadTreeNode Text="Test">
                    <Nodes>
                        <telerik:RadTreeNode Text="Testing1">
                        </telerik:RadTreeNode>
                        <telerik:RadTreeNode Text="Testing12"></telerik:RadTreeNode>
                    </Nodes>
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Text="Testing123">
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeView>
    </telerik:RadPane>
    <telerik:RadSplitBar ID="fileExSplit1" CollapseMode="Backward" runat="server" />
    <telerik:RadPane ID="fileExPane2" runat="server">
        <telerik:RadGrid ID="grdFiles" Width="100%" runat="server" AllowMultiRowSelection="true"
            onneeddatasource="grdFiles_NeedDataSource"
             >
            <SelectedItemStyle BackColor="Red" />
            <MasterTableView ShowHeader="true" UseAllDataFields="false" AutoGenerateColumns="false" RetrieveAllDataFields="false">
                <Columns>
                    <telerik:GridTemplateColumn HeaderText="File Name" >
                        <HeaderStyle Width="50%" />
                        <ItemTemplate>
                            <img src="/internetsite/Images/Icons/<%# Convert.ToBoolean(Convert.ToString(DataBinder.Eval(Container.DataItem, "Title")).Contains("."))? Convert.ToString(DataBinder.Eval(Container.DataItem, "Title")).Substring(Convert.ToString(DataBinder.Eval(Container.DataItem, "Title")).LastIndexOf(".") + 1) + ".gif" : "folder.gif" %>" /> <%# DataBinder.Eval(Container.DataItem, "Title") %>
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings EnableRowHoverStyle="true">
                <Selecting AllowRowSelect="true" />
            </ClientSettings>
        </telerik:RadGrid>
    </telerik:RadPane>
</telerik:RadSplitter>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
  
using Telerik.Web.UI;
  
public partial class UserControls_TreeAndGrid : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            data = data1;
        }
  
    }
  
    GridData[] data1 = new GridData[] { new GridData(1, "Andy"), new GridData(2, "Christian"), new GridData(3, "Johnathan"), new GridData(4, "Tristan") };
    GridData[] data2 = new GridData[] { new GridData(5, "Joe"), new GridData(6, "Jeff"), new GridData(7, "Rice"), new GridData(8, "Brett"), new GridData(9, "Tracy") };
    GridData[] data;
    protected void grdFiles_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        grdFiles.DataSource = data;
    }
  
    protected void rtFiles_NodeClick(object sender, RadTreeNodeEventArgs e)
    {
        data = data2;
        grdFiles.Rebind();
    }
  
    public class GridData
    {
        public GridData(int id, string title) 
        {
            this.Id = id;
            this.Title = title;
        }
        public string Title
        {
            get
            {
                return title;
            }
            set
            {
                title = value;
            }
        }
        private string title;
  
        public int Id
        {
            get
            {
                return id;
            }
            set
            {
                id = value;
            }
        }
        private int id;
  
    }
}


0
Ryan Dailey
Top achievements
Rank 1
answered on 05 Aug 2010, 07:23 PM
I tested the control inside of a simple ASP.NET web application, and the grid works as expected.  However, when I tried to use it in Sitefinity 3.7, row selection is lost after updating the grid with AJAX.  All of this was inside of a blank master page with nothing in it but the basic <head> and <body> tag.
0
Pavlina
Telerik team
answered on 11 Aug 2010, 09:33 AM
Hello Ryan,

In order to persist the selected items after grid rebind, you can try the solution provided in this help article:
http://www.telerik.com/help/aspnet-ajax/grdpersistselectedrowsonsorting.html

Give it a try and let me know how it goes.

Kind regards,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ryan Dailey
Top achievements
Rank 1
answered on 11 Aug 2010, 02:13 PM
No, I'm not wanting to persist selected items.  What I said is that the grid loses it's ability to select anything at all.  It breaks the javascript.  This happens when you update anything on the grid via AJAX when it is placed inside a Sitefinity 3.7 web application.
0
Ryan Dailey
Top achievements
Rank 1
answered on 11 Aug 2010, 08:24 PM
This can be reproduced inside any newly created Sitefinity 3.7 web application.  In the user control listed above, the rows in the grid are selectable starting out.  But, by clicking one of the tree nodes, the grid is updated via AJAX.  After the grid is updated, the rows can no longer be selected.  Hover styles also stop working.
0
Pavlina
Telerik team
answered on 16 Aug 2010, 09:35 AM
Hello Ryan,

My colleague Iana already responded in the support ticket you opened in connection to this subject. To avoid duplicate posts, please continue the communication there if you do not mind.

Greetings,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Ryan Dailey
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Ryan Dailey
Top achievements
Rank 1
Share this question
or