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

Access Data Values from NestedView Table

3 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 23 Aug 2011, 10:35 AM
Hi

I have a Grid with NestedView Table which I create programmatically. 
Each row on the child table has a checkbox field which selects the whole row.
It has a custom Command header with an Image Button which is acting like an "Add to Cart" button.

When the button is clicked, I can access the selected child items like so:

if (e.CommandName == "AddToCart")
{
  if (RadGrid1.SelectedIndexes.Count == 0)
  {
     RadWindowManager1.RadAlert("No documents have been selected", 250, 100, "Add to Document Cart", "");
     return;
  }
  GridCommandItem Item = (GridCommandItem)e.Item;
  ImageButton btnAddToCart = (ImageButton)e.Item.FindControl("btnAddSelectedToCart");
  System.Collections.ArrayList doclist = new System.Collections.ArrayList();
  foreach (GridDataItem item in RadGrid1.SelectedItems)
  {
    doclist.Add(new HRTDocData(Convert.ToInt32(item["RecordID"].Text), Convert.ToInt32(item["DocID"].Text), item["DocTypes"].Text, item["DocReferences"].Text, item["DocContents"].Text));
  }
        }

I actually need to make a javascript call to some existing code with the list of selected items.  I have tried to access the same information from the client side but it isnt working - I just get null values - or not selected???
This is my js function
function GetChildValues() {
    var grid = $find("<%=RadGrid1.ClientID %>");
    var MasterTable = grid.get_masterTableView();
    var selectedRows = MasterTable.get_selectedItems();
    for (var i = 0; i < selectedRows.length; i++) {
        var row = selectedRows[i];
        var cell = MasterTable.getCellByColumnUniqueName(row, "RecordID")
        alert(cell); 
    }

What am I missing please?


 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Aug 2011, 10:49 AM
Hello Simon,

I suppose you want to show the cell text.Show the cell content using cell.innerHTML.
JS:
function GetChildValues()
{
  var grid = $find("<%=RadGrid1.ClientID %>");
  . . . .
  alert(cell.innerHTML);
}

Thanks,
Shinu.
0
Roger
Top achievements
Rank 1
answered on 23 Aug 2011, 11:33 AM
Hi Shinu

Yes, you are correct - however, my problem is that it never reaches that code since the SelectedItems collection always seems to be empty.

ie.
selectedRows.length

is always 0.

*** Sorry - posted from another user name! ***
0
Simon
Top achievements
Rank 1
answered on 23 Aug 2011, 05:20 PM
I have resolved this now by referencing the RadGrid and not the MasterTable. ie.

    var grid = $find('<%=RadGrid1.ClientID %>');
var selectedRows = grid.get_selectedItems();
     if (selectedRows.length != 0) {
     for (var i = 0; i < selectedRows.length; i++) {
          var docReference = selectedRows[i].getDataKeyValue("DocReferences");
          var docId = selectedRows[i].getDataKeyValue("DocID");
          var currRef = selectedRows[i].getDataKeyValue('RecordID');
          alert("Reference: " + docReference + " - DocID = " + docId);
     }
     }
     else {
           radalert('No documents selected', 330, 100, 'Add to Cart', null); 
     }
Tags
Grid
Asked by
Simon
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Roger
Top achievements
Rank 1
Simon
Top achievements
Rank 1
Share this question
or