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

[Solved] Trigger ClientEvent-OnRowSelecting from the server

3 Answers 192 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stuart Hemming
Top achievements
Rank 2
Stuart Hemming asked on 07 Sep 2009, 03:28 PM
A bit of an odd one.

I've a page with a grid on that does all sorts of clever things client-side in the OnRowSelecting event.

Sadly, the client has moved the goal posts and I (under certain circumstances) need to pre-select a row in my server-side code when the page loads.

Now, I know I can rewrite all of the clever JS to perform the same tasks on the server; I just don't want to

So, is there a way of forcing the selection of a row in server-side code that will trigger the client-side OnRowSelecting event? I can, I think, actually use the OnRowSelected event instead, if that's an option.

And, yes, I know I could write a JS function to do stuff and call that using, for example, ResponseScripts.Add(), but I want to access the 'sender' and 'args' parameters that the built-in client-side event exposes.

And thoughts?

--
Stuart

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 08 Sep 2009, 05:37 AM
Hi Stuart,

One suggestion would be calling a custom client method using RegisterStartupScript from code behind and pass the rowindex to that function as parameter. In the client method, get the GridDataItem according to the rowindex passed and select the row explicitly using set_selected() method which will fire the OnRowSelected event. I guess this approach is suitable for you. :)

-Shinu.
0
Stuart Hemming
Top achievements
Rank 2
answered on 08 Sep 2009, 06:56 AM
set_selected()! Clever, I hadn't thought of that! Nice one.

--
Stuart
0
Stuart Hemming
Top achievements
Rank 2
answered on 12 Oct 2009, 01:56 PM

I know it's a little after the event, but I thought I'd let you know that using set_selected() worked insomuch as it selected the item, but it didn't fire the client-side event. However, calling the selectItem() method of the MasterTableView did.

This is the function I used (arg is te row index passed from the server side)...

    function Row_Select(arg) {  
      var mt = $find("<%= RadGrid1.ClientID %>").get_masterTableView();  
      var row = mt.get_dataItems()[arg];  
      mt.selectItem(row.get_element());  
    } 

-- 

Stuart

Tags
Grid
Asked by
Stuart Hemming
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Stuart Hemming
Top achievements
Rank 2
Share this question
or