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

[Solved] How to get dataItem on client from SelectedIndexChanged in Combobox

4 Answers 543 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve White
Top achievements
Rank 1
Steve White asked on 20 Oct 2009, 03:06 PM
I have the following set up in markup, which is inside a multi level hierarchy:

                    <rad:GridTemplateColumn HeaderText="Permission"
                        <ItemTemplate> 
                            <rad:RadComboBox ID="rcbParentCategoryPermission" runat="server" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged"></rad:RadComboBox> 
                        </ItemTemplate> 
                    </rad:GridTemplateColumn> 
 

In JS I have this:

function OnClientSelectedIndexChanged(sender, eventArgs) { 
    var row = sender.get_element().parentNode.parentNode; 
    // how to get the rowindex from this? 

What I want to do is get the gridrow so I can expand/collapse the hierarchy when the combobox index is changed on the client. I've tested that my client hierarchy is looping and expanding all levels correctly. I did this by adding the RowClick handler on the grid. Now all I want to do is find the current rowindex when the combobox value is changed on the client. It feels like it should be simple, but I've been trying to do it for hours.

thanks,

Steve


4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Oct 2009, 05:18 AM
Hi Steve,

I tried declaring a global variable (for saving index) and set the value in OnRowMouseOver event handler, so that we can access the index in combo event. Here is the code that I tried.

JavaScript:
 
<script type="text/javascript"
    var index; 
    function OnClientSelectedIndexChanged() { 
        alert(index); 
    } 
    function RowMouseOver(sender, eventArgs) {  
        index = eventArgs.get_itemIndexHierarchical(); 
    } 
</script> 

-Shinu.
0
Steve White
Top achievements
Rank 1
answered on 21 Oct 2009, 07:08 AM
Shinu -

Thanks. That's exactly the route I've taken so far. The problem with this is that it's not foolproof. In other words, it's possible to click the combobox and change a selected item without triggering the mouseover event on the grid row.

I'm looking for something more reliable and am now looking into adding an Attribute for the combobox inside the ItemDataBound event of the grid. It looks like it's working so far but I'm continuing to test.

I would have thought there would be an inbuilt client method to handle control events within grid rows but I can't find one.

cheers,

Steve
0
Steve White
Top achievements
Rank 1
answered on 22 Oct 2009, 09:28 AM
A couple more questions on this:

1) I have passed the grid RowIndex as an attribute to the ComboxBox and have alerted it back out on the client when ComboBox index is changed. How to I get the grid data item using get_dataItems()[rowindex]? I have a hierarchical grid so I'd need to also know the tableView on the client.

2) Is there a way to set an OnClientFocus event on the ComboxBox so that I can get the grid rowIndex and store it in a global javascript variable like you have done with the gridrow mouseover event?

All I need to do is handle an event in the ComboBox on the client to allow me to get access to the current row in the grid, so that Ii can then expand the grid when the combobox index is changed.

cheers,

Steve
0
Steve White
Top achievements
Rank 1
answered on 22 Oct 2009, 11:45 AM
I managed to solve this by adding attributes to the list items during the ItemDataBound event of the grid:

lItem.Attributes.Add("RowIndex"CStr(item.ItemIndexHierarchical)) 
lItem.Attributes.Add("TableView", e.Item.OwnerTableView.ClientID) 
 

Then in the OnClientSelectedIndexChanged event of the combobox I grab the attributes:

var rowindex = item.get_attributes().getAttribute(""RowIndex""); 
var tableViewId = item.get_attributes().getAttribute(""TableView""); 
var tableView = $find(tableViewId); 
selectedrow = tableView.get_dataItems()[rowindex]; 

Now I can recursively loop each level in the hierarchy, expand them and set the values of all child comboboxes client side.

cheers,

Steve





Tags
Grid
Asked by
Steve White
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Steve White
Top achievements
Rank 1
Share this question
or