Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It would seem that you are interested in binding dictionary values to the accordion. To take advantage of data binding, you should use the control's templates instead of explicitly defining the accordion panes. For example:</p> <pre><code>&lt;cc1:Accordion ID="Accordion1" runat="server" FadeTransitions="True" SelectedIndex="0" HeaderCssClass="accordionHeader" ContentCssClass="accordionContent" Width="370px"&gt; &lt;HeaderTemplate&gt; &lt;h2&gt;&lt;asp:Label runat="server" Text='&lt;%# Eval("Key") %&gt;' /&gt;&lt;/h2&gt; &lt;/HeaderTemplate&gt; &lt;ContentTemplate&gt; &lt;div&gt;&lt;asp:Label runat="server" Text='&lt;%# Eval("Value") %&gt;' /&gt;&lt;/div&gt; &lt;/ContentTemplate&gt; &lt;/cc1:Accordion&gt; </code></pre> <hr> <p>Now, if your dictionary values are complex objects, which may be true since you describe having multiple controls in your content, you can still bind to the dictionary. Consider the slightly-more-involved dictionary below. For simplicity in demonstration, the dictionar values are simple matching anonymous types:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { Dictionary&lt;string, object&gt; dic = new Dictionary&lt;string, object&gt;(); dic.Add("key1", new { Color = "Red", Age = 15 }); dic.Add("key2", new { Color = "Green", Age = 25 }); Accordion1.DataSource = dic; Accordion1.DataBind(); } </code></pre> <p>You can "chase down" the properties in your data binding expressions with an accordion configured like so:</p> <pre><code>&lt;cc1:Accordion ID="Accordion1" runat="server" FadeTransitions="True" SelectedIndex="0" HeaderCssClass="accordionHeader" ContentCssClass="accordionContent" Width="370px"&gt; &lt;HeaderTemplate&gt; &lt;h2&gt;&lt;asp:Label runat="server" Text='&lt;%# Eval("Key") %&gt;' /&gt;&lt;/h2&gt; &lt;/HeaderTemplate&gt; &lt;ContentTemplate&gt; &lt;div&gt;&lt;asp:Label runat="server" Text='&lt;%# Eval("Value.Color") %&gt;' /&gt;&lt;/div&gt; &lt;div&gt;&lt;asp:Label runat="server" Text='&lt;%# Eval("Value.Age") %&gt;' /&gt;&lt;/div&gt; &lt;/ContentTemplate&gt; &lt;/cc1:Accordion&gt; </code></pre> <p>Notice that the only important difference is the dot-notation in the <code>Eval</code> statements.</p> <hr> <p>If, on the other hand, the dictionary value is (or contains) a <em>collection</em> of objects, it is a small matter to embed more advanced ASP.NET controls in your content template. Consider the following dictionary:</p> <pre><code>var dic = new Dictionary&lt;string, IEnumerable&lt;object&gt;&gt;(); dic.Add("key1", new List&lt;object&gt;() { new { Color = "Red" }, new { Color = "Blue" } }); dic.Add("key2", new List&lt;object&gt;() { new { Color = "Yellow" }, new { Color = "Orange" } }); </code></pre> <p>Suppose the intent is to present each of the colors within the same content area. This can be accomplished by databinding the dictionary value to a repeater, like so:</p> <pre><code>&lt;cc1:Accordion ID="Accordion1" runat="server" FadeTransitions="True" SelectedIndex="0" HeaderCssClass="accordionHeader" ContentCssClass="accordionContent" Width="370px"&gt; &lt;HeaderTemplate&gt; &lt;h2&gt;&lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Eval("Key") %&gt;' /&gt;&lt;/h2&gt; &lt;/HeaderTemplate&gt; &lt;ContentTemplate&gt; &lt;asp:Repeater ID="repeater" runat="server" DataSource='&lt;%# Eval("Value") %&gt;'&gt; &lt;ItemTemplate&gt; &lt;div&gt;&lt;asp:Label runat="server" Text='&lt;%# Eval("Color") %&gt;' /&gt;&lt;/div&gt; &lt;/ItemTemplate&gt; &lt;/asp:Repeater&gt; &lt;/ContentTemplate&gt; &lt;/cc1:Accordion&gt; </code></pre> <hr> <p>Happy coding!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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