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

Render Grid

1 Answer 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
lampy
Top achievements
Rank 1
lampy asked on 04 Jun 2008, 04:49 AM
Hello,

Is it possible to render a usercontrol containing an ASP.Net AJAX RadGrid via to string?  I have tried and failed and wanted to see if anyone has gotten it to work.  The code that I use to render is below.

public static string RenderView(string path, object data)  
{  
    Page pageHolder = new Page();  
    UserControl viewControl = (UserControl)pageHolder.LoadControl(path);  
 
    if (data != null)  
    {  
        Type viewControlType = viewControl.GetType();  
        PropertyInfo propertyInfo = viewControlType.GetProperty("DetailsDataSource");  
 
        if (propertyInfo != null)  
        {  
            propertyInfo.SetValue(viewControl, data, null);  
        }  
        else 
        {  
            throw new Exception("View file: " + path + " does not have a public Data property");  
        }  
    }  
 
    pageHolder.Controls.Add(viewControl);  
 
    StringWriter output = new StringWriter();  
    HttpContext.Current.Server.Execute(pageHolder, output, false);  
 
    return output.ToString();  

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 06 Jun 2008, 01:44 PM
Hi lampy,

Unfortunately such scenario is not supported. The RadGrid control needs a real page with it's lifecycle.

Let us know if further questions arise.

Best wishes,
Rosen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
lampy
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or