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

Need Datasource not firing !!

3 Answers 380 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Waleed Seada
Top achievements
Rank 2
Waleed Seada asked on 31 Dec 2009, 03:34 PM
Dear All,

I can't get it to work ...
I reviewed all the forums post regards the NeedDataSource event handlers all the concepts ....

Here is my Issue:
I create a contentpage that exactly matches the tab loadondemad example :
http://demos.telerik.com/aspnet-ajax/tabstrip/examples/applicationscenarios/loadondemand/defaultcs.aspx

But the grids on the loaded user-controls doesn't do any sorting or paging although I implement the OnNeedDatasource event which never fires at all (which cause the sorting or paging miss-behavior).

This is my .ascx grid definition code snippet:
<telerik:RadGrid   
    ID="SummaryCreditGrid"   
    runat="server"                            
    AllowSorting="true" 
    AllowPaging="true" 
    PageSize="5" 
    OnNeedDataSource="SummaryCreditGrid_NeedDataSource">  
    <MasterTableView Width="100%"/>  
</telerik:RadGrid> 
The user-control scenario starts when it loaded and then filled with data using the DisplayValues method that receive a business object (summaryCredit[]) and bind it to the radgrid which I change later to use a datatable when I thought it was the problem.
anyway here is the method:
public void DisplayValues(SummaryCredit[] summaryCredit)  
{  
    DataTable tdt = new DataTable();  
    tdt.Columns.Add("DATA_FROM"typeof(string));  
    tdt.Columns.Add("CATALOGUE_CODE"typeof(string));  
    tdt.Columns.Add("CREDITFACILITY"typeof(string));  
 
    foreach (var credit in summaryCredit)  
    {  
        tdt.Rows.Add(credit.DataFrom, credit.CatalogueCode, credit.Creditfacility);  
    }  
    SummaryCreditGrid.DataSource = tdt;  
    SummaryCreditGrid.DataBind();  
    Session["SummaryCreditGrid"] = tdt;  

and the NeedDataSource method:
protected void SummaryCreditGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
{  
    DataTable dt = new DataTable();  
    dt = Session["SummaryCreditGrid"as DataTable;  
    if (dt != null)  
    {  
        SummaryCreditGrid.DataSource = null;  
        SummaryCreditGrid.DataSource = dt;  
    }  
I put a breakpoint in this method but it never fire !!

What could be my problem ?

Regards
Waleed

3 Answers, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 31 Dec 2009, 04:42 PM
I believe the reason the NeedDataSource event is not firing is because you are applying data to the Grid in the DisplayValues method, which will cause the NeedDataSource event to not fire since the Grid does not need data.
0
Waleed Seada
Top achievements
Rank 2
answered on 01 Jan 2010, 08:44 AM
Hello Schlurk ,

But it is true that I am binding the grid outside the need_datasource event. anyway the execution doesn't reach the breakpoint in the EventHandler "SummaryCreditGrid_NeedDataSource".

Beside the fact that the grid should call that event when sorting or paging, right !

I will try to remove every script only the EventHandler with the breakpoint and see what I will get.

What is your opinion in such case !!

Best regards
Waleed
0
Waleed Seada
Top achievements
Rank 2
answered on 02 Jan 2010, 09:35 AM
Hi Schlurk,

I guess you are right !!

It depends from the very beginning if you use need_datasource or not, I though the event could be used later on with the up coming interaction with the grid, I mean you can't MIX both ways.

Thanks and best regards
Waleed
Tags
Grid
Asked by
Waleed Seada
Top achievements
Rank 2
Answers by
Schlurk
Top achievements
Rank 2
Waleed Seada
Top achievements
Rank 2
Share this question
or