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

Add Dropdown list to Edit Manager Programatically

1 Answer 12 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neal
Top achievements
Rank 1
Neal asked on 26 Oct 2016, 08:25 PM

I have a RadGrid where the data source is set programmatically because the data source will change based on the option the user selects. Some data sources have more columns than the others. When I have the edit item panel displayed to insert a new record I am removing a text box and adding a drop down in its place and populating the drop down from the database and selecting the value that was in the textbox. I can get this to display but when I click the insert button the page blows up because when the page gets to the init event it wants to bind the old one. any advice on how I can get around this?

here is a ajax error that I get every time I try and do an insert/update

Sys.WebForms.PageRequestManagerServerErrorException: Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.  For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 31 Oct 2016, 01:26 PM
Hi Neal,

Generally, when you are changing the grid columns dynamically, you can check the approach demonstrated in the following article:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/changing-the-grid-structure-dynamically-on-postback

Adding and handling controls programmatically can be error-prone, therefore, you can use Panels and toggle their visibility depending on the dropdown's selection:
Copy Code
<EditFormSettings EditFormType="Template">
    <FormTemplate>
        <asp:Panel ID="GridInsertPanel" runat="server" Visible='<%# Container is IGridInsertItem %>'>
            Inserting...
        </asp:Panel>
        <asp:Panel ID="GridEditPanel" runat="server" Visible='<%# !(Container is IGridInsertItem) %>'>
            Editing...
        </asp:Panel>
    </FormTemplate>
</EditFormSettings>

in your case, instead of FormTemplate, you can use the EditItemTemplate of the GridTemplateColumn.

I hope this will prove helpful.


Regards,
Eyup
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Tags
Grid
Asked by
Neal
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or