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

Radgrid webservice client side binding 'loses' has wrong datakey

3 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rosemary
Top achievements
Rank 1
Rosemary asked on 12 Jul 2011, 10:24 AM

We have a radgrid that gets bound in 2 different ways. This depends on what action has been performed on the page..e.g

1. select comboboxA - will bind radgrid via server side binding using NeedDataSource event
2. select comboboxB - will bind radgrid via page method + client side binding . Below are are the the main 2 javascript functions in use .

function GetDataForGrid() {     PageMethods.GetDataForGrid(GetDataForGridBy_Result, GetDataForGridByHeader_Failed);}

  

function GetDataForGrid_Result(result) { 

    var tableView = $find("<%=RadGrid.ClientID %>").get_masterTableView(); 

    tableView.set_dataSource(result.Value);

    tableView.dataBind();

}

 

The problem is, after the client side binding, if the user clicks on a certain row we need to do some processing in a server side event -  RadGrid_ItemCommand(object sender, GridCommandEventArgs e) ...
However when we obtain the datakey within this server side event, it is  always wrong....  

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 15 Jul 2011, 01:33 PM
Hello Rosemary,

Since the grid is bound client-side, it is just normal that the DataKeyValues for the MasterTableView be not populated on the server. However, you can get the data key value for a given row in the OnRowClick client-side event of the grid and send it to the server through the RadAjaxManager control as follow:

function rowClicked(sender, args)
{
 
    var id = args.getDataKeyValue("EmployeeID");
 
    $find('<%= RadAjaxManager1.ClientID %>').ajaxRequest(id):
 
}

On the server, you should attach an event handler to the RadAjaxManager's OnAjaxRequest event that will be thrown by the code given above.

Hope it helps.All the best,
Tsvetoslav
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Rosemary
Top achievements
Rank 1
answered on 15 Jul 2011, 01:48 PM
Thanks for your reply

Is there any other radgrid client event I can use rather than OnRowClick ? currently I need process a click from a GridButtonColumn.

Before your reply, I discovered that I could use the OnCommand client side radgrid event.. however I feel like the code to get the datakey mght not be so efficient,  is there a better way?  Please see my code below

function

RadGrid_Command(sender, args) {  

    if (args.get_commandName() == "commandX"
    {
  
            var itemIndex = args.get_commandArgument(); 

 

            var masterTableView = sender.get_masterTableView();  

            var myId = masterTableView.get_dataItems()[itemIndex].getDataKeyValue("ID"); 

            (.........extra code to populate a hidden hml input field which we then reference on the server   side event: RadGrid_ItemCommand ...)

    }
}

0
Tsvetoslav
Telerik team
answered on 19 Jul 2011, 02:59 PM
Hello Rosemary,

Your approach is a valid and viable one - a hidden input element is an alternative solution as well. 

Regards,
Tsvetoslav
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Rosemary
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Rosemary
Top achievements
Rank 1
Share this question
or