Today, I saw a section on the Internet Code This is about repeater nesting. I hope you can help me solve this problem;
First look at the running effect:
XML file:
<? XML version = "1.0" encoding = "UTF-8" ?>
< Books >
< Book Type = "Computer" >
< Context > C Language </ Context >
< Context > C # Language </ Context >
< Context > C ++ Language </ Context >
</ Book >
< Book Type = "Fiction" >
< Context > Love Novels </ Context >
< Context > Zhiyin Novels </ Context >
< Context > Military Dynamics </ Context >
</ Book >
</ Books >
Background code:
Code
Protected Void Page_load ( Object Sender, eventargs E)
{
Dataset DS = New Dataset ();
DS. readxml (server. mappath ( " Test. xml " ));
Repeater1.datasource = DS;
Repeater1.databind ();
}
Protected Void Repeaterincluitemdatabound ( Object Sender, repeateritemeventargs E)
{
If (E. Item. itemtype = Listitemtype. Item | E. Item. itemtype = Listitemtype. alternatingitem)
{
Repeater P = (Repeater) E. Item. findcontrol ( " Repeater2 " );
Datarowview DRV = (Datarowview) E. Item. dataitem;
P. datasource = DRV. createchildview ( " Book_context " );
P. databind ();
}
}
Front-end code:
< ASP: repeater ID = " Repeater1 " Runat = " Server " Onitemdatabound = " Repeaterincluitemdatabound " >
< Headertemplate >
Repeater Test </ Headertemplate >
< Footertemplate >
</ Footertemplate >
< Itemtemplate >
< Ul >
<% # Eval ( " Type " ) %>
< BR />
</ Ul >
< ASP: repeater ID = " Repeater2 " Runat = " Server " >
< Itemtemplate >
<% # Eval ( " Context_text " ) %> < BR />
</ Itemtemplate >
</ ASP: Repeater >
</ Itemtemplate >
</ ASP: Repeater >
What is unknown is:
1. P. datasource = DRV. createchildview ("book_context"); In "book_context", why is this parameter changed to another parameter? An error is returned:
The createchildview Method on msdn is described as follows:
If You can use Of Method To create Contains the rows in the relevant sub-table. It only describes the relationship between the parent table and the sub-table;
2. Code on the previous page
Code
code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/
--> itemtemplate >
<% # eval ( " context_text " ) %> Br />
itemtemplate >
When setting the context in XML, only the context_text field can be used. If you change it to context, an error is returned. However, according to our general understanding, it should be a field in XML!
I have asked my friends in the garden to solve this problem. Thank you very much!