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

[Solved] Grid issue when using inside a dynamic loaded usercontrol

3 Answers 199 Views
Grid
This is a migrated thread and some comments may be shown as answers.
NewB
Top achievements
Rank 1
NewB asked on 07 Jan 2010, 01:10 PM
Hi,

I am following the example on http://demos.telerik.com/aspnet-ajax/ajax/examples/manager/dynamicajaxsettings/defaultcs.aspx.
It works fine, so I updated it a bit to move the external form into the usercontrols and updated related code like find control and ajax setting registration etc, I then add code to dynamically load the EmployeesGrid usercontrol by follow the logic in this post http://www.telerik.com/help/aspnet-ajax/ajxloadusercontrols.html

I can load the user control, and select then delete item on the grid by using the grid's command button.

However, if I click edit to load a row into the external form and click update or delete button in the external form, I got exceptions.

For example, if I press the delete button on debug mode, and debug into the event hander below:
protected void Delete_Click(object sender, EventArgs e)
    {
        //RadGrid employeesGrid = (this.FindControl("EmployeesGrid1").FindControl("RadGrid1") as RadGrid);
       // RadGrid1 now in the same user control as the external form so can reference directly
        (RadGrid1.SelectedItems[0] as GridDataItem).FireCommandEvent("Delete", string.Empty);
    }
RadGrid1's SelectedItems count always is 0. So seems the status is not persist during the ajax postback.

So I created another simple user control with another RadGrid with paging. Then if dynamically load that usercontrol, the paging seems not working. I add a OnPageIndexedChange event handler and put a break point inside it, the code flow after I page the grid to page 2 is:
main aspx page page_load which load the usercontrol
usercontrol page_load
grid NeedDataSource is called (note: current page index on the grid at this point is still 0)
grid PageIndexChanged is called and the event argument's NewPageIndex is 1, but current page index of the grid is still 0.

So I am confused what the code flow should be, did I missed something? What should I do to make these two examples working?

Many thanks in advance for your time.



3 Answers, 1 is accepted

Sort by
0
NewB
Top achievements
Rank 1
answered on 07 Jan 2010, 03:33 PM
A follow up to the paging issue in the second example above.

If I disable the grid viewstate, it will call the needDataSource again after the pageIndexedChanged event handler is called.

But this is a hack I think, there should be a way to make the pageIndexedChanged event handler called before needDataSource when viewstate is on?
0
Radoslav
Telerik team
answered on 08 Jan 2010, 02:34 PM
Hi NewB,

It is hard to say what is causing this problem without debugging the probloematic page or at least checking out your code. Can you please provide us a simple project we could test?. You could open a formal support ticket from your Telerik account and attach a ZIP file there. We will check it and do our best to help.

As for your second issue: This problem usually occurrs when there is wrong databinding. Could you please provide a simple project for this case as well?
Also I do not suggest you to disable the RadGrid ViewState. When its ViewState is disabled, RadGrid needs to rebind on every postback, because there is no other way it can restore its previous state.
Typically RadGrid stores in ViewState only items/controls collection, not data source data. Some operations in Telerik RadGrid like data extraction through the ExtractValuesFromItem method, grouping, hierarchical views expand/collapse, automatic data source operations, custom edit forms (WebUserControl and FormTemplate) or filtering require ViewState.

Regards,
Radoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
NewB
Top achievements
Rank 1
answered on 08 Jan 2010, 07:49 PM
Hi,

Thank you very much for the reply,  I have submitted an example with support ticket 271869 :-)
Tags
Grid
Asked by
NewB
Top achievements
Rank 1
Answers by
NewB
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or