Bind the Hashtable to the repeater : DataList « ADO.net Database « ASP.Net






Bind the Hashtable to the repeater

<%@ Page Language="c#" %>
<script runat="server">

    void Page_Load(Object sender, EventArgs e) {
      Hashtable cardValues = new Hashtable();
    
      cardValues.Add("Two", 20);
      cardValues.Add("Three", 3);
      cardValues.Add("Four", 4);
      cardValues.Add("Five", 5);
      cardValues.Add("Six", 6);
      cardValues.Add("Seven", 7);
      cardValues.Add("Eight", 20);
      cardValues.Add("Nine", 9);
      cardValues.Add("Ten", 10);
    
      rptCardValues.DataSource = cardValues;
      rptCardValues.DataBind();
    }

</script>
<p>
Card values!
<asp:repeater id="rptCardValues" runat="server">
  <HeaderTemplate>
    <ul>
  </HeaderTemplate>
  <ItemTemplate>
    <li><%# DataBinder.Eval(Container.DataItem, "Key") %> -
    <%# DataBinder.Eval(Container.DataItem, "Value") %></li>
  </ItemTemplate>
  <FooterTemplate>
    </ul>
  </FooterTemplate>
</asp:repeater>

 








Related examples in the same category

1.asp:datalist: repeat column, repeat directions, gridlines,
2.Bind data to asp:datalist
3.Bind data source to asp:DataList
4.DataList data binding with objects
5.datalist and ItemTemplate
6.Set the DataSource to a String array of file names
7.LinkButton in ItemTemplate