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

Dynamically created user control with Radgrid - Events are not working

1 Answer 190 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Xabier
Top achievements
Rank 1
Xabier asked on 17 May 2017, 11:31 PM

Hi,

I will try to explain the scenario the best way possible. I hope you can help me.

I have a page which has one user control with filters. Those filters are displayed dynamically with some information we have stored in the database. Depending on what you select in those filters, the page has to load dynamically one or more user controls with the results (each one will have a radgrid). For example, if in the filter "department", you select the departments A, B, C and D, after clicking in "Submit", we have to create four different result user controls because each department has different columns to display. So having one non-dynamic user control with a radgrid is not an option. Also I have tried having a non-dynamic user control, but creating radgrids dynamically and the results wasn't good. I have to say that I have this scenario fully working with asp.net gridviews, but I need to have better performance and more functionality. This is the main reason of using this telerik control.

I don't have any problem loading the data, but with the radgrid events (sorting, paging), the whole page does a postback and the radgrids are not there.

I'm using advanced server side binding, but I have tried simple binding too with the same result.

 

- The relevant code in the page is. This is called when you select the filters and you click in "Submit":

01.public void GetReports(List<ReportModel> reports)
02.{
03.    int count = 1;
04.    foreach (ReportModel report in reports)
05.    {
06.        DataSet ds = ReportData.GetReportData(report); // If there's no data, this function always return a dataset with one datable informing that there's no data available
07.    foreach (DataTable dt in ds.Tables)
08.        {
09.            ReportResults control = this.LoadControl("~/Reports/Controls/ReportResults.ascx") as ReportResults;
10.            control.ID = string.Format("reportResults{0}", count);
11.            control.Data = data;
12.            this.pnlResults.Controls.Add(control);
13.        }
14.    }
15.}

 

- The client side code in the user control:

<telerik:RadAjaxPanel id="pnlReport" runat="server" cssclass="panel-body nopadding" style="width: 100%; overflow: auto;">
    <telerik:radgrid id="radgrid" runat="server" cssclass="table table-striped table-hover" borderstyle="Solid"
        autogeneratecolumns="true" allowpaging="true" allowsorting="true" rendermode="Lightweight" skin="Bootstrap" onneeddatasource="radgrid_NeedDataSource">
        <pagerstyle mode="NextPrevNumericAndAdvanced" />
    </telerik:radgrid>
</telerik:RadAjaxPanel>

 

- The server side code in the user control:    

01.public DataTable Data
02.{
03.      get
04.      {
05.            return (DataTable)this.ViewState["Data"];
06.      }
07.      set
08.      {
09.             this.ViewState["Data"] = value;
10.      }
11.}
12. 
13. 
14.protected void radgrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
15.{
16.       (sender as RadGrid).DataSource = this.Data; //I have already debugged the code and I have seen that this property has data and it's displayed when I click in "Submit"
17.}

 

Thank you for your help.

1 Answer, 1 is accepted

Sort by
0
Xabier
Top achievements
Rank 1
answered on 19 May 2017, 06:34 PM
I finally find the issue. I just had to reload the control again in the page load event of the page.
Tags
Grid
Asked by
Xabier
Top achievements
Rank 1
Answers by
Xabier
Top achievements
Rank 1
Share this question
or