D
Douglas J. Badin
I wanted to have a hierarchical DataGrid so I created a User Control that
has a DataGrid to act as the Child Grid. I put it inside a pageable Parent
Grid with a page size of one as below in Parent.aspx.
<%@ Register Tagprefix="ABC" Tagname="ChildDataGrid" Src="ucChild.ascx" %>
<ASP
ATAGRID
id="dgParent"
runat="server"
showfooter="true"
allowpaging="true"
pagesize="1"
OnPageIndexChanged="dgParent_PageIndexChanged"
datakeyfield="PK"
datamember="Parent"
<COLUMNS>
<ASP:TEMPLATECOLUMN runat="server" headertext="">
<ITEMTEMPLATE>
....
<ABC:ChildDataGrid
id="ucChild1"
runat="server"
FK='<%# Convert.ToInt32(DataBinder.Eval(Container, "DataItem.PK")) %>'
/>
....
</ITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>
</COLUMNS>
</ASP
ATAGRID>
I have properties, "FK" for the User Control (ucChild.ascx) that hold the
values of the relationship between the Parent and Child Grid. These are
assigned in the Parent.aspx
Initially, I DataBind the ParentDataGrid, which sets the properties of the
User Control and then the Page_Load in the UserControl DataBinds the Child
as follows
1 - Parent.aspx.cs: Page_Load: ParentDataGrid.DataBind()
2 - ucChild.ascx.cs: Properties are set because values are assigned to the
"ucChild1" attributes in the Parent.aspx
3 - ucChild.ascx.cs: Page_Load: ChildDataGrid.DataBind()
No problems so far.
Paging in the Parent Control causes a Page_Load with PostBack to the Parent
Page and User Control. It then fires the PageIndexChanged event which sets
the CurrentPageIndex and re-binds the Parent. This causes another Page_Load
in the User Control which is also viewed as a Post Back and then the
properties of the User Control are set.
1 - Parent.aspx.cs: Page_Load with PostBack
2 - ucChild.ascx.cs; Page_Load with PostBack
3 - Parent.aspx.cs: dgParent_PageIndexChanged: Set CurrentPageIndex
4 - ucChild.ascx.cs: Page_Load with PostBack: ChildDataGrid.DataBind()
5 - ucChild.ascx.cs: Properties are set because values are assigned to the
"ucChild1" attributes in the Parent.aspx
PROBLEM: In the Life-Cycle, the properties were set after the Page_Load on a
PostBack.
For now I have put the ucChild.ascx.cs PostBack code in the PreRender and
things seem to be working.
QUESTION 1: Maybe I should add a RaisePostBackEvent and do it there?
QUESTION 2: Why the difference of when the ucChild.ascx.cs properties are
set depending on PostBack or not?
Thanks,
Doug
has a DataGrid to act as the Child Grid. I put it inside a pageable Parent
Grid with a page size of one as below in Parent.aspx.
<%@ Register Tagprefix="ABC" Tagname="ChildDataGrid" Src="ucChild.ascx" %>
<ASP
id="dgParent"
runat="server"
showfooter="true"
allowpaging="true"
pagesize="1"
OnPageIndexChanged="dgParent_PageIndexChanged"
datakeyfield="PK"
datamember="Parent"
<COLUMNS>
<ASP:TEMPLATECOLUMN runat="server" headertext="">
<ITEMTEMPLATE>
....
<ABC:ChildDataGrid
id="ucChild1"
runat="server"
FK='<%# Convert.ToInt32(DataBinder.Eval(Container, "DataItem.PK")) %>'
/>
....
</ITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>
</COLUMNS>
</ASP
I have properties, "FK" for the User Control (ucChild.ascx) that hold the
values of the relationship between the Parent and Child Grid. These are
assigned in the Parent.aspx
Initially, I DataBind the ParentDataGrid, which sets the properties of the
User Control and then the Page_Load in the UserControl DataBinds the Child
as follows
1 - Parent.aspx.cs: Page_Load: ParentDataGrid.DataBind()
2 - ucChild.ascx.cs: Properties are set because values are assigned to the
"ucChild1" attributes in the Parent.aspx
3 - ucChild.ascx.cs: Page_Load: ChildDataGrid.DataBind()
No problems so far.
Paging in the Parent Control causes a Page_Load with PostBack to the Parent
Page and User Control. It then fires the PageIndexChanged event which sets
the CurrentPageIndex and re-binds the Parent. This causes another Page_Load
in the User Control which is also viewed as a Post Back and then the
properties of the User Control are set.
1 - Parent.aspx.cs: Page_Load with PostBack
2 - ucChild.ascx.cs; Page_Load with PostBack
3 - Parent.aspx.cs: dgParent_PageIndexChanged: Set CurrentPageIndex
4 - ucChild.ascx.cs: Page_Load with PostBack: ChildDataGrid.DataBind()
5 - ucChild.ascx.cs: Properties are set because values are assigned to the
"ucChild1" attributes in the Parent.aspx
PROBLEM: In the Life-Cycle, the properties were set after the Page_Load on a
PostBack.
For now I have put the ucChild.ascx.cs PostBack code in the PreRender and
things seem to be working.
QUESTION 1: Maybe I should add a RaisePostBackEvent and do it there?
QUESTION 2: Why the difference of when the ucChild.ascx.cs properties are
set depending on PostBack or not?
Thanks,
Doug