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

Dynamic dropdwonlist in edit form template

1 Answer 68 Views
UI for ASP.NET AJAX in ASP.NET MVC
This is a migrated thread and some comments may be shown as answers.
Reginald Ware
Top achievements
Rank 1
Reginald Ware asked on 04 May 2010, 06:33 PM
Hello,

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" > 
                <Columns> 
                    <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" /> 
                </Columns> 
                <EditFormSettings EditFormType="Template"
                <FormTemplate> 
                    <table> 
                         
                        <tr> 
                            <td><h3>Doctor Details:</h3></td
                        </tr> 
                        <tr> 
                           <td>Name:</td> 
                           <td><asp:TextBox ID="txtDoctorname" runat="server" Text = '<%# Eval("DoctorName") %>'></asp:TextBox></td
                           <td>Category:</td> 
                           <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> 
                                </asp:DropDownList> 
                                 
                           </td> 
                              <td>Profile type:</td> 
                           <td> 
                                <asp:DropDownList ID="drpProfile" runat="server"
                                     
                                </asp:DropDownList> 
                                 
                           </td> 
                        </tr> 
                    </table> 
                 
                </FormTemplate> 
                 
                </EditFormSettings> 
                 
            </MasterTableView> 
            </telerik:RadGrid>  

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

Thanks,

1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 10 May 2010, 01:08 PM
Hello Reginald,

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

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;
                }
                break;
            case 22:
                {
                    ...
                }
                break;
            case 14:
                {
...
                }
                break;
            default:
                break;
        }
        drpProfile.DataBind();
}

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,
Radoslav
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.
Tags
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Reginald Ware
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or