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?
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));
}
}
{
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;
}