Dynamic dropdwonlist in edit form template

Thread is closed for posting
2 posts, 0 answers
  1. Reginald Ware
    Reginald Ware avatar
    1 posts
    Member since:
    Apr 2010

    Posted 04 May 2010 Link to this post


    I have a code like this:
             <telerik:RadGrid runat="server" ID="RadGrid1" Skin="WebBlue" PagerStyle-AlwaysVisible="true" GridLines="Horizontal" AutoGenerateColumns="true" OnNeedDataSource="RadGrid1_NeedDataSource"  AllowAutomaticInserts="True" AllowAutomaticUpdates="True" OnUpdateCommand="RadGrid1_UpdateCommand" AllowPaging="true" PageSize="20" OnItemDataBound="RadGrid1_ItemDataBound1"
                    <MasterTableView AutoGenerateColumns="false" DataKeyNames="DoctorId" > 
                        <telerik:GridBoundColumn  HeaderText="DoctorId" DataField="DoctorId" UniqueName="DoctorId" Visible="false" /> 
                        <telerik:GridBoundColumn  HeaderText="Name" DataField="DoctorName" UniqueName="Name" /> 
                        <telerik:GridBoundColumn  HeaderText="Category" DataField="Category" UniqueName="Category" /> 
                        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" /> 
                    <EditFormSettings EditFormType="Template"
                                <td><h3>Doctor Details:</h3></td
                               <td><asp:TextBox ID="txtDoctorname" runat="server" Text = '<%# Eval("DoctorName") %>'></asp:TextBox></td
                                    <asp:DropDownList ID="drpCategory" runat="server"
                                        <asp:ListItem Text="Physician" Value="23" Selected="True"></asp:ListItem> 
                                        <asp:ListItem Text="Dentist" Value="14"></asp:ListItem> 
                                        <asp:ListItem Text="Alt Medicine" Value="22"></asp:ListItem> 
                                  <td>Profile type:</td> 
                                    <asp:DropDownList ID="drpProfile" runat="server"

    How do I generate second drop down list "drpProfile" dynamically in code behind  based on selected value of "drpCategory" list?
    Please, help.

  2. Radoslav
    Radoslav avatar
    1564 posts

    Posted 10 May 2010 Link to this post

    Hello Reginald,

    To achieve the desired functionality you could try ajaxifying the RadGrid:
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />

    Then on drpCategory.SelectedIndexChanged event handler you could get the selected value and based on it to populate the drpProfile DropDownList:
    protected void drpCategory_SelectedIndexChanged(object sender, EventArgs e)
            DropDownList drpCategory = (sender as DropDownList);
            DropDownList drpProfile = ((sender as DropDownList).NamingContainer as GridEditFormItem).FindControl("drpProfile") as DropDownList;
            drpProfile.DataTextField = "TextField";
            drpProfile.DataValueField = "ValueField";
            switch (Convert.ToInt32(drpCategory.SelectedValue))
                case 23:
                        drpProfile.DataSource = data;
                case 22:
                case 14:

    Additionally I am sending you a simple example which demonstrates the desired functionality. Please check it out and let me know if it helps you.

    Kind regards,
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top