470,594 Members | 1,120 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,594 developers. It's quick & easy.

Binding Custom Collections to Datagrid

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>
Sep 21 '06 #1
1 1793
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.

"Suresh" wrote:
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>
Sep 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by craig | last post: by
5 posts views Thread by Dalibor Kusic | last post: by
6 posts views Thread by GingerNinja | last post: by
3 posts views Thread by Just D | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.