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

[Solved] Edit doesn't select the row

3 Answers 68 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Darwin
Top achievements
Rank 1
Darwin asked on 05 Mar 2013, 10:30 PM
I have a page with two RadGrids on it.  When a row in the left grid is selected, the right grid is refreshed to show data pertinent to the row that was selected in the left grid.   This all works great, until somebody clicks Edit on a different row than the was currently selected.  The right grid refreshes but still shows data for the row that was previously selected, not for the row that is now being edited.  I solved the problem this way:

        protected void rgRegion_EditCommand(object sender, GridCommandEventArgs e)
        {
            var item = e.Item as GridDataItem;
            item.Selected = true;

            if (rgRegion.SelectedItems.Count > 0)
            {
                rgRegionAcct.Rebind();
            }
        }

This works great UNLESS, while the row in the left grid is still in Edit Mode, the user clicks the Add link in the right grid.  At this point, as the right grid tries to lookup the selected row in the left grid, the left grid no longer has a row selected.  

        protected void rgRegionAcct_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            try
            {
                int? selectedRegionId = GetSelectedRegionId();
                rgRegionAcct.DataSource = GetRegionAccountsTable(selectedRegionId);
            }
            catch (Exception ex)
            {
                Utilities.LogError("Retrieving Account/Region Configuration", ex.Message, ex.StackTrace, "");
                ShowPopup(String.Format("There was an error loading the account/region configuration.  The error was {0}", ex.Message));
            }
        }

        private int? GetSelectedRegionId()
        {
            int? returnValue = null;

            if (rgRegion.SelectedItems.Count > 0)
            {
                var gridDataItem = rgRegion.SelectedItems[0] as GridDataItem;
                if (gridDataItem != null)
                {
                    returnValue = Convert.ToInt32(gridDataItem.GetDataKeyValue("RegionId"));
                }
            }

            return returnValue;
        }

It appears that the left grid is refreshing for some unknown reason.  There is no rebind() being called on the left grid when the Add link is clicked on the right grid.  So why is my left grid refreshing which I assume is the reason row, that is in update mode, is no longer selected?

3 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 11 Mar 2013, 08:16 AM
Hello Darwin,

Note that when Insert command is fired the grid will perform a postback even without explicitly called the Rebind method. You will experience the same behavior for Update and Delete command. 

Kind regards,
Kostadin
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
Darwin
Top achievements
Rank 1
answered on 11 Mar 2013, 02:57 PM
There are two grids on the page.  Clicking insert on grid 2 is supposed to cause grid 1 to refresh?
0
Kostadin
Telerik team
answered on 14 Mar 2013, 01:05 PM
Hello Darwin,

It is hard to determine the reason for that behaviour without your code declaration. Could you confirm that you do not ajaxified your grid? If you have an axaj settings that the right grid updates the left grid this will rebind the left grid.

Greetings,
Kostadin
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.
Tags
Grid
Asked by
Darwin
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Darwin
Top achievements
Rank 1
Share this question
or