Hi folks,
Here's a weird problem...
I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the OnSelectedIndex Changed event set on it. This triggers just fine, but within the codebehind of the OnSelectedIndex Changed event, I need to scan through all the entries in the nested GridView (to see if the user changed a value to an already existing value in the list). My problem is that I can't seem to get a handle on the nested GridView.
Here's an example (simplified from my actual code for readability):
Down in the codebehind for EmployeeName_Se lectedIndexChan ged, I can get the row that changed and such with the following:
But the last call to get the GridView item so I can scan through all the records always returns null. I'm sure it's because the code is looking for the GridView within the row and, of course, it doesn't exist there. It exists in the outer GridView's row. So how do I get a handle on this inner GridView?
Many thanks for any help.
Robert
Here's a weird problem...
I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the OnSelectedIndex Changed event set on it. This triggers just fine, but within the codebehind of the OnSelectedIndex Changed event, I need to scan through all the entries in the nested GridView (to see if the user changed a value to an already existing value in the list). My problem is that I can't seem to get a handle on the nested GridView.
Here's an example (simplified from my actual code for readability):
Code:
<asp:GridView ID="EmployeeGroupsGridView" runat="server" /> <Columns> <asp:TemplateField HeaderText="ID"> <ItemTemplate> <asp:Label ID="employee_group_id" runat="server" Text='<%# Bind("employee_group_id") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Employees"> <ItemTemplate> <asp:GridView ID="EmployeeGroupEmployeesGridView" runat="server" OnRowCommand="EmployeeGroupEmployeesGridView_RowCommand" OnRowDataBound="EmployeeGroupEmployeesGridView_RowDataBound"> <Columns> <asp:TemplateField> <ItemTemplate> <asp:Label ID="recno" runat="server" Text='<%# Bind("recno") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <ItemTemplate> <asp:DropDownList id="employee_name" DataSourceID="SqlDataSourceEmployeeNamesPlus" Runat="Server" OnSelectedIndexChanged="EmployeeName_SelectedIndexChanged" AutoPostBack="true" DataTextField="employee_name" DataValueField="employee_name" SelectedValue='<%# Bind("employee_name") %>'/> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>
Code:
DropDownList ddl = (DropDownList)sender; Control senderControl = (Control)sender; GridViewRow row = (GridViewRow)senderControl.NamingContainer; GridView gv = (GridView)row.FindControl("EmployeeGroupEmployeesEditGridView");
Many thanks for any help.
Robert
Comment