New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Operations with MS DropDownList in EditItemTemplate of GridTemplateColumn

This article discusses how to bind a dropdown control in EditItemTemplate with custom values and update the ItemTemplate field after editing. The functionality can be used in cases in which the developer may want to provide different list of choices than the ones present by default in GridDropDownColumn. You should locate the dropdown control in the ItemDataBound handler of the grid for each item which is in edit mode and bind it to the data source of your choice. Furthermore, when update is performed you can save the selected by the user value in Session variable and then set that value for the template column cell in regular mode.The same Session variable can be used to select the default item in the dropdown control on subsequent editing.

In the code below we assign array of ListItem objects as data source for the dropdown editor. To visualize clearly the functionality depicted above we generate only one grid item. For more complex scenarios you should adjust the provided logic to suit your case.

ASP.NET
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" AutoGenerateColumns="False">
    <MasterTableView>
        <Columns>
            <telerik:GridBoundColumn UniqueName="ContactName" ReadOnly="True" HeaderText="ContactName"
                DataField="ContactName" />
            <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Country">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server"
                        Text='<%# DataBinder.Eval(Container.DataItem, "Country") %>'>
                    </asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="List1" runat="server" />
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
Not finding the help you need?
Contact Support