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

[Solved] How can I get the grid data on the onrowselect event

3 Answers 530 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joao Araujo
Top achievements
Rank 1
Joao Araujo asked on 06 Oct 2009, 10:01 PM
Hello,

  I have a grid where I want to access the object containing the data at client side, in order to present details of the object
  in another panel of the page. I have tried several variations to access the underline object and dataitem values without success.
  I maybe overlooking the solutions somehow.

  Here is a portion of my javascript . Nothing that I tried worked yet. I tried many variations of the below without success. Only the index value shows correctly on my page.

 
               function OnRowSelected(sender, eventArgs)
                    {
                        var grid = $find("<%=TradesGrid.ClientID %>");

                        var index = eventArgs.get_itemIndexHierarchical();   
                        var master = grid.get_masterTableView();         
                        var row = master.get_dataItems()[index];
                        var newValues = master.extractValuesFromItem(index);
                        var newValuesSB = new Sys.StringBuilder();
                       
                        newValuesSB.append("this is a test </br>");
                        for(var property in newValues)
                        {          
                        newValuesSB.append(String.format("<b>{0}</b> : {1} <br/>", property,newValues[property]));
                        }  
                        document.getElementById("<%= QuantityDetail.ClientID %>").innerHTML = "123" + index;
                        document.getElementById("<%= PriceDetail.ClientID %>").innerHTML = newValuesSB.toString();                      
                        document.getElementById("<%= InitialLoan.ClientID %>").innerHTML =row["InitialLoan"];

   

  Thanks.

Joao,

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 07 Oct 2009, 04:23 AM
Hi Joao,

Try out the following client side code in order to get the row value in OnRowSelecting event.

JavaScript:
 
<script type="text/javascript"
    function OnRowSelected(sender, eventArgs) { 
        var grid = sender; 
        var MasterTable = grid.get_masterTableView(); 
        var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()]; 
        var cell = MasterTable.getCellByColumnUniqueName(row, "ContactName"); 
        alert(cell.innerHTML); //here cell.innerHTML holds the value of the cell 
    } 
</script> 
Also checkout the documentation on this:
Getting cell values for selected rows client side

-Shinu.
0
Joao Araujo
Top achievements
Rank 1
answered on 19 Oct 2009, 01:04 AM
Thanks for your help.

It enlightened me on some other possibilities. 
Is there a way to access the other properties of the object, not declared in the bound column list? 



Thanks
0
Accepted
Princy
Top achievements
Rank 2
answered on 19 Oct 2009, 04:36 AM
Hello Joao,

You can set the fields that are not visible in the grid as datakeynames of the grid and then access it on rowselected client event as explained in the document below:
Extracting key values client-side

Thanks
Princy.
Tags
Grid
Asked by
Joao Araujo
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Joao Araujo
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or