Trigger the JS clientEvent OnRowSelected from code behind.

0 Answers 49 Views
Ajax Grid
Didier
Top achievements
Rank 2
Iron
Iron
Didier asked on 13 Mar 2023, 08:25 PM | edited on 13 Mar 2023, 11:02 PM

Hi all,

 

I have 2 RadGrid.

When a row is selected on the first Radgrid and if the second RadGrid contain only one value (after populating it) => 


I can from the code behind of the first RadGrid select the first and only row of the second via the code behind (OnSelectedIndexChanged event on the first Radgrid).

 

RadGrid2.MasterTableView.Items[0].Selected = true;

But the  JS code <ClientEvents OnRowSelected="RowSelected"/>  of the second is never called.

 

 

If I click on the row, the JS event is called correctly.

I try via a call =>


ScriptManager.RegisterStartupScript(this.Page, GetType(), "Selected", "RowSelected()", true);

But without succes => get an error =>

Uncaught TypeError: Cannot read properties of null (reading 'get_masterTableView')

Any suggestion ? 

Regards,

Didier

 

Attila Antal
Telerik team
commented on 16 Mar 2023, 11:52 AM

Hi Didier.

You are correct, the RowSelected client-side event of the Grid only happens if the row is selected on the client. If you render the Grid with a selected row, only the selected state and the styles are shown, nothing triggers the RowSelected event.

Can you give us some more information about what you're trying to achieve? What are you trying to do in the "RowSelected" event or why is it needed?

Didier
Top achievements
Rank 2
Iron
Iron
commented on 16 Mar 2023, 11:58 AM | edited

Hi

 

tanks for your reply.

The view is composed of Two Grid and a panel with detailed information of the selected row (second grid).

 

I wanted to 'emulate' a click or a selection, because the detail is updated when a row is selected on the second grid.

the customer requested when we selected a value on the 1st GRid and the Grid 2 contains only one result, he want to see this row selected and display the details.

So, since the code to update the details panel is on the Client side .. I'm looking to use the same code.

Regards,

Didier

Attila Antal
Telerik team
commented on 16 Mar 2023, 12:51 PM | edited

Thank you for the clarification. 

I am assuming you have a code that binds data to Grid2 when a selection in Grid1 happens. That is working when you interact with Grid1 on the client and can be left intact.

You can add one additional code in the Page PreRender event that will count the number of items in the Grid. If the result returned is less than 2, select the item and also make the other Grid bind to data based on this item.

 

 

Didier
Top achievements
Rank 2
Iron
Iron
commented on 16 Mar 2023, 01:18 PM

Tx for your reply.

So, I have two GRid.

The OnNeedDataSource is used to populate it (via database SP).

When a row is selected on the Grid1, the OnSelectedIndexChanged is called (code behind) and I Rebind() the Grid 2.
In the same code, If only one row exist in the Grid2, I 'm selecting it. (=> but no event triggered :/ 


if (RadGridVIG.MasterTableView.Items.Count ==1)
{
      GridItem item = RadGridVIG.MasterTableView.Items[0];
      item.Selected = true; // mark the item as selected
}

The Grid 2 in the OnNeedDataSource, check which row has been selected in the Grid1, and made the good query.

If i select a row on the Grid 2, the OnRowSelected (client event) is called with an ajax call who get the data to display on a detail panel.

The code to display the detail is on the OnRowSelected event of the Grid2. 

How to call it ?

Attila Antal
Telerik team
commented on 17 Mar 2023, 11:06 AM

Currently, you are Rebinding Grid2 when the SelectedIndexChanged event of Grid1 is triggered. That is how Grid2 gets bound to data based on the selected value.

Now, imagine that you load the page and Grid1 only has 1 item. You mark the item as selected, and immediately after that, you can follow up with Grid2.Rebind(). You do not need to let the app complete the Page Loading, only to make another round-trip back to the server and call Rebind on Grid2.

Does this make sense?

No answers yet. Maybe you can help?

Tags
Ajax Grid
Asked by
Didier
Top achievements
Rank 2
Iron
Iron
Share this question
or