find combobox

4 posts, 0 answers
  1. Tina
    Tina avatar
    130 posts
    Member since:
    Jul 2011

    Posted 01 Nov 2011 Link to this post

    I have a radcombobox in itemtemplate of grid.how to access the datakeyvalue?
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 01 Nov 2011 Link to this post

    Hello Tina,

    Try the following code snippet in SelectedIndexChanged event of RadComboBox.
    C#:
    protected void combo_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
      RadComboBox combo = (RadComboBox)sender;
      GridDataItem item = (GridDataItem)combo.NamingContainer;
      string id = Convert.ToInt32(item.GetDataKeyValue("ID")).ToString();
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Tina
    Tina avatar
    130 posts
    Member since:
    Jul 2011

    Posted 02 Nov 2011 Link to this post

    Thanks Shinu.
    But i want to access hte row in which combobox is present and then access the datakeyvalue.how can it be done?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Nov 2011 Link to this post

    Hello Tina,

    In order to get the datakeyvalue, attach the event OnClientSelectedIndexChanged from server side and pass the index.
    C#:
    protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
         {
            GridDataItem dataItem = (GridDataItem)e.Item;
            RadComboBox combo = (RadComboBox)dataItem.FindControl("Radcombo");
           int index = e.Item.ItemIndex;
           combo.OnClientSelectedIndexChanged = "function (sender,args){rowIndex('" + index + "');}";             
         }
    }

    Javascript:
    function rowIndex(index)
    {
       var row = $find('<%= RadGrid1.ClientID %>').get_masterTableView().get_dataItems()[index];
       alert(row.getDataKeyValue("ID"));//DataKeyName
    }

    Thanks,
    Shinu.
Back to Top