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

How ti reselect datagrid row?

10 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Goran
Top achievements
Rank 1
Goran asked on 16 Jul 2012, 07:33 AM
Hi,

I have 2 rad grids. First one is master and second one is detail. I can delete rows from both grids independently by pressing "Delete" button on toolbar above each grid. I also have "Refresh" buttons in toolbar of both grids.

The problem is with detail grid. When I delete item(s) the grid doesn't refresh. Calling Rebind method doesn't help. The only thing that helps is to press "Refresh" button in toolbar of master grid and select the row in master grid by mouse that was previously selected. After that I can see refreshed detail grid.

So, I don't need to press "Refresh" button in toolbar of master grid and select the row in master grid by mouse. I can refresh the master grid programmatically and only want to reselect the item that was originally selected also programmatically. I've tried this:

item.Selected = true;

But, it only visually selects the item in master grid and doesn't refresh the detail grid.

So, how to select the item in master grid programmatically in order to get the same effect as selecting it by mouse?

Thank you in advance.

10 Answers, 1 is accepted

Sort by
0
Goran
Top achievements
Rank 1
answered on 17 Jul 2012, 07:54 AM
Could someone, please, help with this issue?

Once again, I need to programmatically select some item in rad grid, but not only visually. I need to raise SelectedIndexChanged event.
0
Goran
Top achievements
Rank 1
answered on 17 Jul 2012, 12:28 PM
Or to be more simple - if I select some item (row) in master grid by mouse it reflects in detail grid. All is fine. After that I deleted some items (rows) in detail grid, but detail grid doesn't refresh. How can I reselect the item (row) in master grid, which originally was selected programmatically? I've tried this as well:

item.Selected = false;
item.Selected = true;

But, it doesn't work.
0
Accepted
Eyup
Telerik team
answered on 17 Jul 2012, 12:42 PM
Hi Goran,

Could you please try to  use the following approach?
  mark-up:
<ClientSettings EnablePostBackOnRowClick="true">
  code-behind:
protected void RadGrid1_DeleteCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    RadGrid1.Items[RadGrid1.SelectedIndexes[0]].FireCommandEvent("Select", String.Empty);
}

That should do the trick.

Regards,
Eyup
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
Goran
Top achievements
Rank 1
answered on 19 Jul 2012, 07:21 AM
Thank you Eyup.

This doesn't help because we don't use standard rad grid "Delete" button, which means DeleteCommand event doesn't fire up. We have our own "Delete" button on toolbar right above the grid. I simply want to reselect the same item that was originally selected after deletion items in details grid.

We don't use Telerik's rad grid directly. It's wrapped inside our control. That makes things a little bit harder, but it should work.

Once again, I'm selecting an item in master grid and some items appear in detail grid. All is fine. After that I'm deleting some items from detail grid and nothing happens. After that, when I select some other item in master grid by mouse and select again originally selected item by mouse I see new refreshed content of detail grid without deleted items. Of course I don't want from our users to do the same selection by mouse. I need to reselect the originally selected item programmatically.
0
Eyup
Telerik team
answered on 23 Jul 2012, 08:33 AM
Hello Goran,

Since you are using a custom delete command, you will need to hook up to your button click event and Rebind() your detail tableview upon deleting an item. Alternatively of course, you could also do that on client side.

Actually, it is difficult to determine your exact scenario without the project's mark-up and the related code-behind. Please open a support ticket and provide us a sample runnable application demonstrating the issue. Thus, we will be able to further analyze the application and provide a more-to-point solution.

Greetings,
Eyup
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
Goran
Top achievements
Rank 1
answered on 24 Jul 2012, 05:47 AM
Eyup,

In the meantime I resolved the issue I had. But, thank you anyway.

Generally speaking, I'm trying to add new functionality to old code, which is very tightly connected to database. And my data source is not database. Also, the overall architecture is not so flexible, which means I need to do some kind of hack to make it work.

At this moment only one issue remains and I'd like to ask you for help. My detail grid has pager at the bottom (paging data). How can I access pager from outside of rad grid control in order to refresh the grid?
0
Shinu
Top achievements
Rank 2
answered on 24 Jul 2012, 06:51 AM
Hello,

Try the following code to access pager item from external click.
C#:
protected void Button1_Click(object sender, EventArgs e)
{
 foreach (GridDataItem item in RadGrid2.MasterTableView.Items)
 {
   GridTableView tableView = (GridTableView)item.ChildItem.NestedTableViews[0];
   foreach (GridPagerItem pager in tableView.GetItems(GridItemType.Pager))
   {
     RadComboBox combo = (RadComboBox)pager.FindControl("PageSizeComboBox");
   }
  }
}

Thanks,
Shinu.
0
Goran
Top achievements
Rank 1
answered on 24 Jul 2012, 07:25 AM
It's crashing on this line:

GridTableView tableView = (GridTableView)item.ChildItem.NestedTableViews[0];

The message is:

Object reference not set to an instance of an object.
0
Goran
Top achievements
Rank 1
answered on 24 Jul 2012, 07:40 AM
What exactly I need is to get some signal that I clicked something (page number: 1, 2, 3... or combo box with number of items per page) in pager in order to refresh rad grid. That signal should be flag that I can use after to write something like this:

[C#]
if(pagerClicked)
  RefreshGrid();

Telerik's rad grid control is incorporated into our own user control.
0
Shinu
Top achievements
Rank 2
answered on 25 Jul 2012, 09:35 AM
Hello,

Unfortunately I cannot replicate the issue at my end. Here I am pasting the full code that I tried which worked as expected.
aspx:
<telerik:RadGrid runat="server" ID="RadGrid2" EnableLinqExpressions="false" AutoGenerateColumns="False" OnNeedDataSource="RadGrid2_NeedDataSource" OnDetailTableDataBind="RadGrid2_DetailTableDataBind" AllowPaging="true">
   <MasterTableView Name="master" DataKeyNames="CustomerID" CommandItemDisplay="Top">
        <Columns>
         <telerik:GridBoundColumn HeaderText="CustomerID" DataField="CustomerID" UniqueName="CustomerID"></telerik:GridBoundColumn>
        </Columns>
        <DetailTables>
           <telerik:GridTableView  AllowPaging="true" PageSize="4" AutoGenerateColumns="false">
            <Columns>
             <telerik:GridBoundColumn HeaderText="OrderID" DataField="OrderID" UniqueName="OrderID"></telerik:GridBoundColumn>
            </Columns>
            <ParentTableRelation>
                <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" />
            </ParentTableRelation>
         </telerik:GridTableView>
       </DetailTables>
   </MasterTableView>
</telerik:RadGrid>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

C#:
protected void Button1_Click(object sender, EventArgs e)
{
 foreach (GridDataItem item in RadGrid2.MasterTableView.Items)
 {
   GridTableView tableView = (GridTableView)item.ChildItem.NestedTableViews[0];
   foreach (GridPagerItem pager in tableView.GetItems(GridItemType.Pager))
   {
     RadComboBox combo = (RadComboBox)pager.FindControl("PageSizeComboBox");
     string value = combo.SelectedValue.ToString();
   }
 }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Goran
Top achievements
Rank 1
Answers by
Goran
Top achievements
Rank 1
Eyup
Telerik team
Shinu
Top achievements
Rank 2
Share this question
or