PC Review


Reply
Thread Tools Rate Thread

Binding Custom Collections to Datagrid

 
 
=?Utf-8?B?U3VyZXNo?=
Guest
Posts: n/a
 
      21st Sep 2006
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>
 
Reply With Quote
 
 
 
 
=?Utf-8?B?U3VyZXNo?=
Guest
Posts: n/a
 
      22nd Sep 2006
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>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Advantages of using custom collections over datatables to bind to a datagrid? John Dalberg Microsoft ASP .NET 4 8th Dec 2005 07:39 PM
datagrid custom binding expression =?Utf-8?B?cm9kY2hhcg==?= Microsoft ASP .NET 2 21st Nov 2005 05:46 AM
Binding a datagrid to a System.Collections member Sathyaish Microsoft ASP .NET 1 6th Sep 2005 04:26 AM
Binding a datagrid to a System.Collections member Sathyaish Microsoft VB .NET 1 6th Sep 2005 04:26 AM
Binding a datagrid to a System.Collections member Sathyaish Microsoft Dot NET Framework 1 6th Sep 2005 04:25 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:52 AM.