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

How to get radgrid row index

1 Answer 1474 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 22 May 2011, 12:20 AM
Hi,

I'm using a rad combo box control in rad grid with an itemtemplate. Can you tell me how to get the row index on selected index change?

Thanks,

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 May 2011, 05:39 AM
Hello Ron,

If you want to access the rowindex from the sreverside SelectedIndexChanged event, access the GridDataItem using the property NamingContainer of the RadComboBox. Here is the sample code that I tried. Hope this helps you.

C#:
protected void ddlItems_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
   {
    RadComboBox combo = sender as RadComboBox;
    GridDataItem item = (GridDataItem)combo.NamingContainer;
    int index = item.ItemIndex;
   }
    

In order to get rowindex from clientside attach client event OnClientSelectedIndexChanged and then pass  the parameters. Since radcontrols expect only  default parameters(sender,arguments)  assign anonymous function and then pass the extra parameters.

C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
 {
        if (e.Item is GridDataItem)
       {
         GridDataItem item = (GridDataItem)e.Item;
         RadComboBox combobox = (RadComboBox)item.FindControl("ddlItems");
        combobox.OnClientSelectedIndexChanged = "function (button,args){Selected('" + item.ItemIndex + "');}";
   }
  }

Javascript:
<script type="text/javascript">
   function Selected(rowIndex)
    {
        alert(rowIndex);
    }
</script>

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