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

GridTemplateColumns Dynamic Dropdowns

1 Answer 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 21 Nov 2008, 11:19 PM
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>
-------------------------------------------------------------------------

1 Answer, 1 is accepted

Sort by
0
SamJ
Top achievements
Rank 1
answered on 22 Nov 2008, 10:49 AM
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; 

Tags
Grid
Asked by
Matt
Top achievements
Rank 1
Answers by
SamJ
Top achievements
Rank 1
Share this question
or