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

Get selected row

1 Answer 226 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 16 Oct 2013, 02:38 PM
I need to be able to get the selected row that contains a combobox when the combobox selectedindex changes.  I have a radgrid that contains a combobox control in one of the columns.  At runtime the combo box is populated and set to the proper selection during the itemdatabound method.  The user can then change the selected item in the combobox which I need to grab other cell values in that same grid row.  All this needs to be done in javascript.  I have found articles where I need to get combobox.parent.parent to get the selected index row which I have been able to achive by doing 

var parent = sender.get_parent;
var grandparent = parent.get_parent;

But have not been able to successfully get the selected row to be able to get values from other cells in that row.  Any suggestions on how to get the information out using javascript would be appreciated

Thanks
Justin

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Oct 2013, 11:17 AM
Hi Justin,

I guess you need to access the row on RadComboBox "OnClientSelectedIndexChanged" event. Please take a look into the following code snippet I tried.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="RadGrid1_ItemDataBound"
        OnItemCreated="RadGrid1_ItemCreated" AutoGenerateColumns="false">
        <MasterTableView>
            <Columns>
                <telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID" HeaderText="OrderID">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn HeaderText="Combobox">
                    <ItemTemplate>
                        <telerik:RadComboBox ID="RadComboBox1" runat="server">
                        </telerik:RadComboBox>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings Selecting-AllowRowSelect="true">
        </ClientSettings>
    </telerik:RadGrid>

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");
        combo.Items.Insert(0, new RadComboBoxItem("item0", "0"));
        combo.Items.Insert(1, new RadComboBoxItem("item1", "1"));
        combo.Items.Insert(2, new RadComboBoxItem("item2", "2"));
        combo.Items.Insert(3, new RadComboBoxItem("item3", "3"));
        combo.Items.Insert(4, new RadComboBoxItem("item4", "4"));
        combo.Items.Insert(5, new RadComboBoxItem("item5", "5"));
        combo.SelectedIndex=3;
    }
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
          
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        int index = item.ItemIndex;
        RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");
        combo.OnClientSelectedIndexChanged = "function(sender, args){OnClientSelectedIndexChanged1(sender, args,'"+index+"' );}";
    }
}

JavaScript:
<script type="text/javascript">
    function OnClientSelectedIndexChanged1(sender, args, index) {
        var grid = $find("<%=RadGrid1.ClientID %>");
        var mastertable = grid.get_masterTableView();
        var dataitem = mastertable.get_dataItems()[index]; //accessing the row in which the RadComboBox selectedIndexChanged event is invoked
        alert(dataitem.get_cell("OrderID").innerHTML); //getting the cell value of the row
    }
</script>

Thanks,
Princy.
Tags
ComboBox
Asked by
Justin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or