Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, I find way to render repeater inside the listview, I don't know if I can paste the whole code because it is pretty long. the result html like following:</p> <pre> <ul> <li>time1 [comment: following is repeater inside listview] scenarioNamegroupName1groupName2 S1g1Conc1g2Conc1 S2g1Conc2g2Conc2 S3g1Conc1g2Conc3 </li> <li>time2 [comment: following is repeater inside listview] scenarioNamegroupName1groupName2 S1g1Conc1g2Conc1 S2g1Conc2g2Conc2 S3g1Conc1g2Conc3 </li> <li>time3 [comment: following is repeater inside listview] scenarioNamegroupName1groupName2 S1g1Conc1g2Conc1 S2g1Conc2g2Conc2 S3g1Conc1g2Conc3 </li> </ul> </pre> <p>The hard part is that the number of group can be different </p> <p>my aspx page like following:</p> <p>...hm...the forum I cannot use verbatim for code, the pre block won't work for some character</p> <pre><code> KeyValuePair&lt;string, List&lt;scenarioItem&gt;&gt; myData = (KeyValuePair&lt;string, List&lt;scenarioItem&gt;&gt;)(((System.Web.UI.WebControls.ListViewDataItem)(e.Item)).DataItem); Repeater repeater = (Repeater)e.Item.FindControl("childData"); repeater.HeaderTemplate = new MyTemplate(ListItemType.Header); repeater.ItemTemplate = new MyTemplate(ListItemType.Item); repeater.AlternatingItemTemplate = new MyTemplate(ListItemType.AlternatingItem); repeater.FooterTemplate = new MyTemplate(ListItemType.Footer); repeater.DataSource = myData.Value; repeater.DataBind(); public class MyTemplate : System.Web.UI.ITemplate </code></pre> <p>{ System.Web.UI.WebControls.ListItemType templateType; public MyTemplate(System.Web.UI.WebControls.ListItemType type) { templateType = type; }</p> <pre><code>static void Item_DataBinding(object sender, System.EventArgs e) { PlaceHolder ph = (PlaceHolder)sender; RepeaterItem ri = (RepeaterItem)ph.NamingContainer; scenarioItem myDataItem = (scenarioItem)ri.DataItem; if (ri.ItemIndex == 0) { //create the header column part once //Add ScenarioName ph.Controls.Add(new LiteralControl("&lt;tr&gt;&lt;td&gt;ScenarioName&lt;/td&gt;")); //Add group concentration part foreach (recGroupConcItem concItem in myDataItem.mGroupConcList) { ph.Controls.Add(new LiteralControl("&lt;td&gt;" + concItem.groupName + @"&lt;/td&gt;")); } ph.Controls.Add(new LiteralControl("&lt;/tr&gt;")); } //Add ScenarioName ph.Controls.Add(new LiteralControl("&lt;tr&gt;&lt;td&gt;"+myDataItem.scenarioName+@"&lt;/td&gt;")); //Add group concentration part foreach (recGroupConcItem concItem in myDataItem.mGroupConcList) { ph.Controls.Add(new LiteralControl("&lt;td&gt;" + concItem.groupConc.ToString() + @"&lt;/td&gt;")); } ph.Controls.Add(new LiteralControl("&lt;/tr&gt;")); } static void ItemAlt_DataBinding(object sender, System.EventArgs e) { PlaceHolder ph = (PlaceHolder)sender; RepeaterItem ri = (RepeaterItem)ph.NamingContainer; scenarioItem myDataItem = (scenarioItem)ri.DataItem; //Add ScenarioName ph.Controls.Add(new LiteralControl("&lt;tr bgcolor=\"lightblue\"&gt;&lt;td&gt;" + myDataItem.scenarioName + @"&lt;/td&gt;")); //Add group concentration part foreach (recGroupConcItem concItem in myDataItem.mGroupConcList) { ph.Controls.Add(new LiteralControl("&lt;td&gt;" + concItem.groupConc.ToString() + @"&lt;/td&gt;")); } ph.Controls.Add(new LiteralControl("&lt;/tr&gt;")); } static void ItemHeader_DataBinding(object sender, System.EventArgs e) { PlaceHolder ph = (PlaceHolder)sender; RepeaterItem ri = (RepeaterItem)ph.NamingContainer; scenarioItem myDataItem = (scenarioItem)ri.DataItem; //Add ScenarioName ph.Controls.Add(new LiteralControl("&lt;tr&gt;&lt;td&gt;ScenarioName&lt;/td&gt;")); //Add group concentration part foreach (recGroupConcItem concItem in myDataItem.mGroupConcList) { ph.Controls.Add(new LiteralControl("&lt;td&gt;" + concItem.groupName + @"&lt;/td&gt;")); } ph.Controls.Add(new LiteralControl("&lt;/tr&gt;")); } public void InstantiateIn(System.Web.UI.Control container) { PlaceHolder ph = new PlaceHolder(); Label item1 = new Label(); Label item2 = new Label(); item1.ID = "item1"; item2.ID = "item2"; switch (templateType) { case ListItemType.Header: ph.Controls.Add(new LiteralControl("&lt;table border=\"1\"&gt;")); // "&lt;tr&gt;&lt;td&gt;&lt;b&gt;ScenarioName&lt;/b&gt;&lt;/td&gt;" + // "&lt;td&gt;&lt;b&gt;Group1&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Group2&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Group3&lt;/b&gt;&lt;/td&gt; &lt;td&gt;&lt;b&gt;Group4&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt;")); //ph.DataBinding += new EventHandler(ItemHeader_DataBinding); break; case ListItemType.Item: ph.DataBinding += new EventHandler(Item_DataBinding); break; case ListItemType.AlternatingItem: ph.DataBinding += new EventHandler(ItemAlt_DataBinding); break; case ListItemType.Footer: ph.Controls.Add(new LiteralControl("&lt;/table&gt;")); break; } container.Controls.Add(ph); } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload