Binding Custom Collections to Datagrid

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>
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top