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

[Solved] Data not bound again after postback on dynamically-loaded RadGrids

2 Answers 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Brian Furner
Top achievements
Rank 2
Brian Furner asked on 15 Sep 2009, 07:14 PM
I have a project in which I have a hierarchical RadGrid contained within a UserControl (usrAccountOverview.ascx).  There is an aspx page that dynamically loads a number of these UserControls based upon which option a user selects in a DropDownList.  The RadGrid binds data just fine at the top of the hierarchy, and if you expand one top-level item in the hierarchy binding works fine within the DetailTable as well.  However, if the page posts back, none of the previously bound data reappears in any expanded DetailTables.

Here is the declarative code for the RadGrid

    <telerik:RadGrid ID="rgMonthly" runat="server" GridLines="None" OnColumnCreated="rgMonthly_ColumnCreated" 
        OnDetailTableDataBind="rgMonthly_DetailTableDataBind" OnItemDataBound="rgMonthly_ItemDataBound" 
        OnNeedDataSource="rgMonthly_NeedDataSource"
        <MasterTableView DataKeyNames="GroupID"
            <DetailTables> 
                <telerik:GridTableView Width="100%" runat="server" DataKeyNames="GroupID"
                    <ParentTableRelation> 
                        <telerik:GridRelationFields DetailKeyField="GroupID" MasterKeyField="GroupID" /> 
                    </ParentTableRelation> 
                </telerik:GridTableView> 
            </DetailTables> 
        </MasterTableView> 
    </telerik:RadGrid> 
 

I am loading the UserControls in the Page_Init method of the aspx page and binding them as in the following:

    protected void Page_Init(object source, System.EventArgs e) 
    { 
        BindSelectedInfo(); 
    } 
 
    protected void BindSelectedInfo() 
    { 
        try 
        { 
            DTSelectedAccts = TAAcctPi.GetData(Int32.Parse(Session["id"].ToString())); 
            for (int i = 0; i < 1; i++) 
            { 
                dsAccountProjections.dtAcctPiRow SelectedAcct = DTSelectedAccts[i]; 
                usrAccountOverview AccountOverview = (usrAccountOverview)LoadControl("~/usrAccountOverview.ascx"); 
                AccountOverview.ID = "usr" + SelectedAcct.SlAcct6Num; 
                AccountOverview.Acct.AcctNum = SelectedAcct.SlAcct6Num; 
                AccountOverview.PullAcctInfo(); 
                pnlHolder.Controls.Add(AccountOverview); 
            } 
        } 
        catch (Exception ex) 
        { 
 
        } 
    } 
 
    protected void rgMonthly_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        if (!e.IsFromDetailTable) 
        { 
            rgMonthly.DataSource = DMonthlyExpenditures.GetMonthlyExpendituresByGroup(_Acct.AcctNum, firstMonthID, lastMonthID, lastMonthID); 
        } 
    } 
 
    protected void rgMonthly_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e) 
    { 
        GridDataItem parentItem = e.DetailTableView.ParentItem; 
        DataTable dtBind = DMonthlyExpenditures.GetMonthlyExpendituresBySubAcct(_Acct.AcctNum, firstMonthID, lastMonthID, lastMonthID, Int32.Parse(parentItem["GroupID"].Text)); 
        if (dtBind.Rows.Count > 0) e.DetailTableView.DataSource = dtBind; 
    } 

Is there some way of getting this to work?

Thanks,

Brian








2 Answers, 1 is accepted

Sort by
0
Brian Furner
Top achievements
Rank 2
answered on 16 Sep 2009, 02:32 PM
I forgot to mention that the RadGrid works just fine if the UserControl that contains it is declaratively placed on the page.  It is only when the UserControl is loaded dynamically in Page_Init that the problem arises.

I would appreciate any guidance.

Brian
0
Brian Furner
Top achievements
Rank 2
answered on 16 Sep 2009, 03:28 PM
It looks like the problem was due to my making a call to RadGrid.Rebind();
Once I commented out that line, things worked as expected.
Tags
Grid
Asked by
Brian Furner
Top achievements
Rank 2
Answers by
Brian Furner
Top achievements
Rank 2
Share this question
or