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

[Solved] Programmatic Creation

8 Answers 184 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Covertix
Top achievements
Rank 1
Covertix asked on 07 Dec 2008, 07:15 PM
Hello All,

I'm trying to create a grid programmatically and am facing some difficulties with regard to PostBack action and/or filtering (error type is dependant on the approach I'm using).
My situation is as follows:
I have a user control that acts as a parent to another user control (ReportMenuBox) and also includes a placeholder (myGridReport). See below:
<div id="ReportPage">  
    <div class="ReportPageConainer">  
        <uc6:ReportMenuBox ID="ReportMenuBox1" runat="server" Text="Reports" /> 
        <div class="myStyle" id="ReportBox">  
            <uc5:RoundedHeader ID="RoundedHeader1" runat="server" /> 
            <div class="myClass">  
            <asp:PlaceHolder ID="myGridReport" runat="server"></asp:PlaceHolder> 
            </div> 
        </div> 
    </div> 
</div> 

The child user control (ReportMenuBox) is a menu in which the user can selects a report type and set the report various parameters. When the user click the submit button in the menu (child user control), in the codebehind I'm creating a grid from scratch and then assign it to the parent placeholder. Everything works fine except to the fact that I can't do any postback operations (pager etc.) because the grid will disappear.
I've tried to change the placeholder to a grid and then build the grid in the child user control based on the parent grid. This approach only works if I call databind or rebind in the child user control, and then I encounter an error with the filtering (index out of range..).

Searching the forum, I only found examples where the codebehind belongs to the displaying user control and thus can be put in the init and page_load, an approach which I can't use.

Any idea would be appreciated.

8 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 09 Dec 2008, 02:49 PM
Hello Tzach,

Indeed RadGrid can be dynamically created and its structure can be changed on postback. However, in order your grid to be fully functional and to work properly, you should create it on Page_Load or on Page_Init. If the grid is created entirely in code behind, as it is in your case, you should create the grid in the Page_Init event handler. Otherwise your grid will not work as desired, as observed already.

Please review this helps article which elaborates more on grid dynamic creation after postback and demonstrates a grid created based on DropDownList control selection.

I hope this helps.

Kind regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Covertix
Top achievements
Rank 1
answered on 14 Dec 2008, 08:53 AM
Hello Iana,
Unfortunatly your proposed solution do not work for me (or maybe I'm not doing it right).
I've changed my design as to be close as possible to your sample.
I now have a user control (report) which contains another user control (menu).
In the code behind of of the report user control, I've placed all the code for the dynamic creation of the grid. I call this function in the Page_Init of the report user control.
My design differ from your example as all the controls that change the structure of the grid are located in the child user control (menu). In the menu user control I set all the report parameters and when a button is clicked an event is triggered. I catch this event in the report user control, and then change the grid accrodingly.
Everyhting is working fine except that paging, sorting, filtering etc. rerturn an "Index out of range" error.

Your help is needed and appreciated.

Regards,
Tzach.
0
Iana Tsolova
Telerik team
answered on 15 Dec 2008, 12:52 PM
Hi,

You need to handle the grid structure changing on Page.Init in order the paging, sorting, filtering, etc. to work properly. Performing the grid structure changing in the button event handler on postback is too late for the grid to be created/restored properly.
Can you try retrieving the report parameters in the report user control Page.Init event handler by requesting the form?

Let me know how it goes.

Greetings,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Covertix
Top achievements
Rank 1
answered on 16 Dec 2008, 11:40 AM
Hi Iana,

I've changed the application and now whenever I click the submit button in the menu user control, I programatically trigger a postback with all the various parameters. I then catch these parameters in the page_init of the report user control and build the grid dynamically.
While it is working well in submit, it still doesn't work when I want to sort, filter etc. This is because when I do filter, sort etc, the controls on the menu user control do not exist.
The sample you provided works because I have a dropdownlist present on the main page. In my case, I build the whole page from scratch.

Any ideas?
TZach.
0
Covertix
Top achievements
Rank 1
answered on 16 Dec 2008, 01:24 PM
Hi Iana,

Up to now i tried several approaches into solving this issue. Each approach had it shortcoming which resulted in wrong functionality.
I would appreciate it if you could point me to a project that resembles what I'm trying to achieve.
I need to dynamically build several different grids (report grids) on same user control, when there is another child user control which is used to set the parameters for the grids.

Your help is appreciated.

Regards,
Tzach.
0
Iana Tsolova
Telerik team
answered on 16 Dec 2008, 01:51 PM
Hello Tzach,

Could you please open a format support ticket and send us there a sample project illustrating the issue? Thus I could better understand your logic and try providing you a resolution.

Regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Covertix
Top achievements
Rank 1
answered on 16 Dec 2008, 02:39 PM
Problem solved.
A combination of programatic postback on the menu user control + use of session object to keep state + some logic on the report user control page_init has done the trick.
Still some minor things to handle but overall it is working.

Thanks,
Tzach.
0
Bob
Top achievements
Rank 1
answered on 13 Aug 2009, 11:37 PM
Hello i would appreciate it if you could POST your solution here for others with the same problem

Thanks much
Tags
Grid
Asked by
Covertix
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Covertix
Top achievements
Rank 1
Bob
Top achievements
Rank 1
Share this question
or