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

RadGrad-how to populate dropdown with selection from another dropdown in editform

2 Answers 337 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Binh
Top achievements
Rank 1
Binh asked on 11 Mar 2011, 07:49 PM

I am using  a radgrid with the command items of insert and edit turned on.  I am using a form template for the edit/insert views.  In my form template i have multiple dropdown menus.  I am able to populate the first dropdown thru the itemDataBound event with no problem.  My question is how would i populate the next dropdown menu with what is selected in the previous drop down menu?    The dropdowns i am referring to are in the gridSections (radgrid) in the below markup.  The ddlQuestion dropdown is populated with data dependant on what is selected in the ddlSection dropdown.  In the selectedIndexChange for ddlSection I would have to access the edit form somehow.  I am not sure how to do this.  Any ideas?

<telerik:radajaxpanel id="radajaxpanel1" runat="server" loadingPanelID="RadAjaxLoadingPanel1">
                   <telerik:radgrid runat="server" id="gridAudits" GridLines="None" Skin="Sunset" 
                       onneeddatasource="gridAudits_NeedDataSource" 
                       onitemdatabound="gridAudits_ItemDataBound" 
                       onitemcommand="gridAudits_ItemCommand" 
                       oninsertcommand="gridAudits_InsertCommand">
                       <mastertableview CommandItemDisplay="Top" AutoGenerateColumns="False" InsertItemPageIndexAction="ShowItemOnCurrentPage" 
                               ShowHeadersWhenNoRecords="true" DataKeyNames="ID,AuditTypeID">                  
                           <CommandItemSettings AddNewRecordText="Add New Assessment" />
                           <NestedViewTemplate>
                               <asp:Panel ID="NestedViewPanel" runat="server" CssClass="viewWrap">
                                   <div class="contactWrap">
                                       <fieldset style="padding: 10px;">
                                           <legend style="padding: 5px;"><b>Section Data:</b>
                                           </legend>
                                               <telerik:radgrid runat="server" id="gridSection" skin="Windows7" 
                                                   OnNeedDataSource="gridSection_NeedDataSource"
                                                   onitemdatabound="gridSection_ItemDataBound" 
                                                   OnDetailTableDataBind="gridSection_DetailTableDataBind"  
                                                   onitemcommand="gridSection_ItemCommand" 
                                                   onprerender="gridSection_PreRender" >
                                                   <mastertableview CommandItemDisplay="Top" AutoGenerateColumns="False" 
                                                           InsertItemPageIndexAction="ShowItemOnCurrentPage" 
                                                           ShowHeadersWhenNoRecords="true" DataKeyNames="ID"
                                                           EditMode="PopUp" >                                                      
                                                       <CommandItemSettings AddNewRecordText="Add" />
                                                       <DetailTables>
                                                           <telerik:GridTableView DataKeyNames="ID" Name="SectionChildren" Width="100%"
                                                               AutoGenerateColumns="False">
                                                               <Columns>                                                            
                                                                   <telerik:GridBoundColumn DataField="Defect" 
                                                                       HeaderText="Child Defect(s)" ReadOnly="True" UniqueName="Defect" />  
                                                               </Columns>
                                                           </telerik:GridTableView>
                                                       </DetailTables>
                                                       <Columns>              
                                                           <telerik:GridEditCommandColumn ButtonType="ImageButton" />
                                                           <telerik:GridBoundColumn DataField="Section" DataFormatString="<nobr>{0}</nobr>" 
                                                               HeaderText="Section" UniqueName="Section" />                                  
                                                           <telerik:GridBoundColumn DataField="Question" 
                                                               HeaderText="Question" UniqueName="Question" />
                                                           <telerik:GridBoundColumn DataField="Result" DataFormatString="<nobr>{0}</nobr>" 
                                                               HeaderText="Result" UniqueName="Result" />
                                                           <telerik:GridBoundColumn DataField="DefectCode" 
                                                               HeaderText="Defect Code" UniqueName="DefectCode" />
                                                           <telerik:GridBoundColumn DataField="UpdatedBy" HeaderText="Updated By" 
                                                               UniqueName="UpdatedBy" DataFormatString="<nobr>{0}</nobr>" />
                                                           <telerik:GridBoundColumn DataField="TimestampLocalTime" DataFormatString="<nobr>{0}</nobr>" 
                                                               HeaderText="Last Updated" UniqueName="TimestampLocalTime" />
                                                           <telerik:GridBoundColumn DataField="Notes" DataFormatString="<nobr>{0}</nobr>" 
                                                               HeaderText="Notes" UniqueName="Notes" />
                                                       </Columns>
                                                       <EditFormSettings InsertCaption="Add new item" CaptionFormatString="Edit item: {0}"
                                                               EditFormType="Template" PopUpSettings-Modal="true" CaptionDataField="ID" PopUpSettings-Width="550px">
                                                           <FormTemplate>
               <telerik:radajaxpanel id="radajaxpanel2" runat="server" loadingPanelID="RadAjaxLoadingPanel1">
                                                               <table>
                                                                   <tr>
                                                                       <td>Section: </td>
                                                                       <td>
                                                                           <asp:DropDownList ID="ddlSection" runat="server" AutoPostBack="true"
                                                                           Visible="<%# (Container is GridEditFormInsertItem) ? true : false %>"
                                                                           OnSelectedIndexChanged="ddlSection_indexchanged" />
                                                                           <asp:Label ID="Label1" runat="server" Text='<%# Bind("Section") %>' 
                                                                           Visible="<%# (Container is GridEditFormInsertItem) ? false : true %>" />
                                                                       </td>
                                                                   </tr>
                                                                   <tr>
                                                                       <td>Question: </td>
                                                                       <td><asp:DropDownList ID="ddlQuestion" runat="server" 
                                                                           Visible="<%# (Container is GridEditFormInsertItem) ? true : false %>"/>
                                                                           <asp:Label ID="Label2" runat="server" Text='<%# Bind("Question") %>' 
                                                                           Visible="<%# (Container is GridEditFormInsertItem) ? false : true %>" />
                                                                           </td>
                                                                   </tr>
                                                                   <tr>
                                                                       <td>Result: </td>
                                                                       <td><asp:DropDownList ID="ddlResult" runat="server" /></td>
                                                                   </tr>
                                                                   <tr>
                                                                       <td>Child Defects: </td>
                                                                       <td><asp:CheckBoxList ID="cblChildDefects" runat="server"></asp:CheckBoxList></td>
                                                                   </tr>
                                                                   <tr>
                                                                       <td>Notes: </td>
                                                                       <td><asp:TextBox ID="TextBox1" runat="server" Height="119px" Text='<%# Bind("Notes") %>' 
                                                                       TextMode="MultiLine" Width="445px" />
                                                                   </td>
                                                                   </tr>
                                                               </table>
                                                               </telerik:radajaxpanel>
                                                                       <asp:Button ID="Button1" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                                                           runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                                                                       </asp:Button
                                                                       <asp:Button ID="Button2" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel">
                                                                       </asp:Button>
                                                           </FormTemplate>
                                                       </EditFormSettings>
                                                   </mastertableview>
                                               </telerik:radgrid>
                                       </fieldset>
                                   </div>
                               </asp:Panel>
                           </NestedViewTemplate>
                           <expandcollapsecolumn visible="True">
                           </expandcollapsecolumn>
                           <Columns>
                               <telerik:GridEditCommandColumn ButtonType="ImageButton" />
                               <telerik:GridTemplateColumn DataField="ID" DataType="System.Int32" 
                                   HeaderText="ID" UniqueName="ID" visible="false">
                                   <EditItemTemplate>
                                       <asp:Label ID="IDTextBox" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
                                   </EditItemTemplate>
                                   <ItemTemplate>
                                       <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>'></asp:Label>
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>
                               <telerik:GridTemplateColumn DataField="AuditType" HeaderText="Audit Type" 
                                   UniqueName="AuditType">
                                   <EditItemTemplate>
                                       <asp:DropDownList ID="ddlAuditType" runat="server" 
                                           DataSource="<%# AuditTypeList %>" DataTextField="ListValue" DataValueField="ID" 
                                           Enabled="<%# (Container is GridEditFormInsertItem) ? true: false %>"  />
                                   </EditItemTemplate>
                                   <ItemTemplate>
                                       <asp:Label ID="AuditTypeLabel" runat="server" Text='<%# Eval("AuditType") %>'></asp:Label>
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>
                               <telerik:GridTemplateColumn DataField="Assessor" HeaderText="Assessor" 
                                   UniqueName="Assessor">
                                   <EditItemTemplate>
                                       <QA:EmployeeLookup id="employeeLookup" runat="server" ></QA:EmployeeLookup>
                                   </EditItemTemplate>
                                   <ItemTemplate>
                                       <asp:Label ID="AssessorLabel" runat="server" Text='<%# Eval("Assessor") %>'></asp:Label>
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>
                               <telerik:GridTemplateColumn DataField="ICB" HeaderText="ICB" UniqueName="ICB">
                                   <EditItemTemplate>
                                       <asp:CheckBox ID="cbICB" runat="server" Text="ICB" />
                                   </EditItemTemplate>
                                   <ItemTemplate>
                                       <asp:Label ID="ICBLabel" runat="server" Text='<%# Eval("ICB") %>'></asp:Label>
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>
                               <telerik:GridTemplateColumn DataField="Status" HeaderText="Status" 
                                   UniqueName="Status">
                                   <EditItemTemplate>
                                       <asp:DropDownList ID="ddlStatus" runat="server" DataSource="<%# StatusList %>" 
                                           DataTextField="ListValue" DataValueField="ListValue" 
                                           Enabled="<%# (Container is GridEditFormInsertItem) ? false: true %>" />
                                   </EditItemTemplate>
                                   <ItemTemplate>
                                       <asp:Label ID="StatusLabel" runat="server" Text='<%# Eval("Status") %>'></asp:Label>
                                   </ItemTemplate>
                               </telerik:GridTemplateColumn>
                               <telerik:GridBoundColumn DataField="TimestampLocalTime" HeaderText="Last Updated" 
                                       UniqueName="TimestampLocalTime" ReadOnly="True"/>
                               <telerik:GridBoundColumn DataField="UpdatedBy" HeaderText="Updated By" 
                                   ReadOnly="True" UniqueName="UpdatedBy" />
                           </Columns>
                           <editformsettings>
                               <editcolumn uniquename="EditCommandColumn1">
                               </editcolumn>
                           </editformsettings>
                           </mastertableview>
                   </telerik:radgrid>    
       </telerik:radajaxpanel>

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Mar 2011, 06:18 AM
Hello Binh,

In order to get the control(ddlQuestion) in edit form, first access the edit form using NamingContainer property of the DropDownList. Then access the control(ddlQuestion) using FindControl method. Check out the following code snippet.

C#:
protected void ddlSection_indexchanged(object sender, EventArgs e)
   {
       DropDownList ddlSection = (DropDownList)sender;
       GridEditFormItem editItem = (GridEditFormItem)ddlSection.NamingContainer;
       DropDownList ddlQuestion = (DropDownList)editItem.FindControl("ddlQuestion");
       //populate 'ddlQuestion' based on selected value of 'ddlSection'
   }

Thanks,
Princy.
0
Binh
Top achievements
Rank 1
answered on 14 Mar 2011, 03:57 PM
Thanks Princy.  That works great!

I was also able to access it with the following:
DropDownList ddlQuestion = (sender as DropDownList).parent.findControl("ddlQuestion") as DropDownList
Tags
Grid
Asked by
Binh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Binh
Top achievements
Rank 1
Share this question
or