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

find combobox

3 Answers 55 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Tina
Top achievements
Rank 1
Tina asked on 02 Nov 2011, 02:31 AM
I have a radcombobox in itemtemplate of grid.how to access the datakeyvalue?

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Nov 2011, 04:59 AM
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.
0
Tina
Top achievements
Rank 1
answered on 02 Nov 2011, 05:22 PM
Thanks Shinu.
But i want to access hte row in which combobox is present and then access the datakeyvalue.how can it be done?
0
Shinu
Top achievements
Rank 2
answered on 03 Nov 2011, 07:27 AM
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.
Tags
Filter
Asked by
Tina
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Tina
Top achievements
Rank 1
Share this question
or