Binding Custom Collections to Datagrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using ASP.NET 1.1
----------------------

I have a custom collection of object that I'm binding to a datagrid. Each
of these objects have another collection inside them. I have a user control
that renders the nested collection into html table. See sample code below.

Now this binds fine and my sub collections are rendered fine by my user
control and list appears as it should. The problem is when I do paging. The
sub collections do not bind.

Any help would be appreciated.

Thank in advance,
Suresh.

<asp:datagrid id='dgTest' runat='server'>
<columns>
<asp:templatecolumn>
<itemtemplate>
<!-- Below is from the main collection -->
<%#DataBinder.Eval(Container.DataItem, "AssignmentStatus"))%>
<!-- Below is from the sub collection -->
<uc1:myusrctrl id="ucmyusrctrl" DataSourceItems='<%#
(MySubCollection) DataBinder.Eval(Container.DataItem, "Items") %>'
runat="server"></uc1:myusrctrl>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
 
Solved this issue.

2 - Things.

1. The actual setting of html inside my usercontrol was happening on
Page_Load of the user control and after I check 'If IsPostBack'. I should've
realized that clicking on a pager link is a postback operation.

2. The event order of page and user controls on postback. On postback the
user control is loaded before it's properties are allowed to be set. So even
when I removed 'If IsPostBack' it still had null for my sub object collection
property.
To solve this I simply moved the html rendering function inside the set
method of the property.

Now all is well.

Suresh.
 
Back
Top