Hi,
I am using RadDropDownList in GridTemplateColumn, and I want to get the row index when SelectedIndexChanged event of RadDropDownList is fired.
My code looks like below:
ASPX:
Code-behind:
I searched in the forum and find some hints as above code snippet, but at line 7, I always get a null reference.
Do you have any advice? Thanks in advance!
I am using RadDropDownList in GridTemplateColumn, and I want to get the row index when SelectedIndexChanged event of RadDropDownList is fired.
My code looks like below:
ASPX:
<telerik:RadGrid runat="server" ID="RadGrid1" AllowSorting="false" AutoGenerateColumns="false" AllowMultiRowSelection="True" GridLines="Both"> <ClientSettings AllowColumnsReorder="false" ReorderColumnsOnClient="False"> <Scrolling AllowScroll="true" UseStaticHeaders="true"></Scrolling> <Resizing AllowColumnResize="true" EnableRealTimeResize="false" /> <Selecting AllowRowSelect="True"></Selecting> </ClientSettings> <GroupingSettings ShowUnGroupButton="False"></GroupingSettings> <MasterTableView EnableHeaderContextMenu="false" EditMode="Batch" > <BatchEditingSettings EditType="Cell" OpenEditingEvent="MouseOver"/> <Columns> <telerik:GridClientSelectColumn Reorderable="False" Resizable="False" > </telerik:GridClientSelectColumn> <telerik:GridBoundColumn DataField="Organ" HeaderText="Organ" Resizable="False" DataType="System.String" ReadOnly="true"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn UniqueName="OptionColumn" HeaderText="Option" Resizable="False"> <ItemTemplate > <%# Eval("Option")%> </ItemTemplate> <EditItemTemplate> <telerik:RadDropDownList ID="MyList" runat="server" DataSourceID="LinqDS1" DataTextField="Text" DataValueField="Value" OnSelectedIndexChanged="MyList_SelectedIndexChanged" AutoPostBack="True"> </telerik:RadDropDownList> </EditItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid><asp:LinqDataSource ID="LinqDS1" runat="server" EnableDelete="False" EnableInsert="False" EnableUpdate="false" OnSelecting="LinqDS1_Selecting"></asp:LinqDataSource>Code-behind:
01.protected void MyList_SelectedIndexChanged(object sender, DropDownListEventArgs e)02.{03. var dropDownList = sender as RadDropDownList;04. if (dropDownList != null)05. {06. // try to get the row index07. var item = dropDownList.NamingContainer as GridDataItem;08. if( item != null )09. {10. sources[ item.RowIndex ] = e.Text;11. }12. }13.}I searched in the forum and find some hints as above code snippet, but at line 7, I always get a null reference.
Do you have any advice? Thanks in advance!
