GridTemplateColumns Dynamic Dropdowns

2 posts, 0 answers
  1. Matt
    Matt avatar
    10 posts
    Member since:
    Nov 2008

    Posted 21 Nov 2008 Link to this post

    Hello,

    I currently have a RadGrid with two GridTemplateColumns with dropdowns. When the first dropdown is changed I need the items in the second dropdown to change based on what was selected in the first. What is the best way to do this from the codebehind? I have the column section of my code shown below. Thanks in advance.
    -------------------------------------------------------------------------------------------
     <telerik:GridTemplateColumn UniqueName="ClientName" HeaderText="Charge To">
                                    <ItemTemplate>
                                        <%# Eval("ClientName")%>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:DropDownList ID="ddlClient" runat="server" DataTextField="ClientName" DataValueField="ClientId"
                                            DataMember="ExpenseId" OnSelectedIndexChanged="ddlClient_SelectedIndexChanged">
                                        </asp:DropDownList>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
                                <telerik:GridTemplateColumn UniqueName="DepartmentName" HeaderText="Department" DataField="DepartmentId">
                                    <ItemTemplate>
                                        <%# Eval("DepartmentName")%>
                                    </ItemTemplate>
                                    <EditItemTemplate>
                                        <asp:DropDownList ID="ddlDepartment" runat="server" DataTextField="DepartmentName"
                                            DataValueField="DepartmentId">
                                        </asp:DropDownList>
                                    </EditItemTemplate>
                                </telerik:GridTemplateColumn>
    -------------------------------------------------------------------------
  2. SamJ
    SamJ avatar
    101 posts
    Member since:
    Jul 2008

    Posted 22 Nov 2008 Link to this post

    You can handle the SelectedIndexChanged event of the first drop down and there change the second drop down control. The below snippet can help you:

    <telerik:GridTemplateColumn UniqueName="ClientName" HeaderText="Charge To"
        <ItemTemplate> 
            <%# Eval("ClientName")%> 
        </ItemTemplate> 
        <EditItemTemplate> 
            <asp:DropDownList AutoPostBack="true" ID="ddlClient" runat="server" DataTextField="ClientName" DataValueField="ClientId" 
                DataMember="ExpenseId" OnSelectedIndexChanged="ddlClient_SelectedIndexChanged"
            </asp:DropDownList> 
        </EditItemTemplate> 
    </telerik:GridTemplateColumn> 
    <telerik:GridTemplateColumn UniqueName="DepartmentName" HeaderText="Department" DataField="DepartmentId"
        <ItemTemplate> 
            <%# Eval("DepartmentName")%> 
        </ItemTemplate> 
        <EditItemTemplate> 
            <asp:DropDownList ID="ddlDepartment" runat="server" DataTextField="DepartmentName" 
                DataValueField="DepartmentId"
            </asp:DropDownList> 
        </EditItemTemplate> 
    </telerik:GridTemplateColumn> 
    protected void ddlClient_SelectedIndexChanged(object sender, EventArgs e) 
        DropDownList ddlClient = sender as DropDownList; 
        GridEditableItem editedItem = ddlClient.NamingContainer as GridDataItem; 
        DropDownList ddlDepartment = editedItem["DepartmentName"].FindControl("ddlDepartment"as DropDownList; 

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top