Nested Data Bound UserControl

I needed to have ASP.NET report with DataRepeater and nested data bound user control.
The similar approach is used in 
ASP.NET Reports Starter Kit  with datagrid nested in datalist itemtemplate.

       <asp:datalist id="CategoriesList" runat="server" >
                <itemtemplate>
                                <asp:datagrid id=Datagrid1 runat="server"  DataSource=''
<%# GetDetails(DataBinder.Eval(Container.DataItem, "CategoryID")) %>'
                                </< FONT>asp:datagrid>
                </< FONT>
itemtemplate
>
                <
headerstyle cssclass="ReportTitle"></< FONT>headerstyle
>
            </< FONT>asp:datalist>
 So my markup should be like this: 

<%@ Register Src="MyUserControl.ascx" TagName="MyUserControl" TagPrefix="uc1" %>

<asp:Repeater ID="Repeater1" runat="server">

<ItemTemplate>

<uc1:MyUserControl  DataSource=<%# GetDetails(DataBinder.Eval(Container.DataItem,"PatronId")) %>

 ReportId= <%# ReportID %> id="patronNotice" runat="server" >

</uc1:OverdueNotice>

</ItemTemplate>

</asp:Repeater>

 

I’ve created DataSource property and on DataBinding event used it to populate my UserControl data.
But it didn’t work. DataBinding event occurred earlier than
DataSource was set from DataBinding expression and  DataSource=Nothing.

I’ve read carefully the DataBinding documentation and understood that
DataBind can be called more than once during the same request and it is important to re-do binding if DataSource property has been changed.
So I had to implement
Data Bound User Control class to resolve the issue.

 

posted @ Saturday, September 16, 2006 12:41 PM
Print

Comments on this entry:

# re: Nested Data Bound UserControl

Left by Michael Freidgeim at 12/2/2007 10:39 PM
Gravatar
Related articles: http://www.codeproject.com/aspnet/RepeaterWithControl.asp
Using Web User Controls in Repeaters and DataList

Your comment:



(not displayed)

 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456