zoukankan      html  css  js  c++  java
  • repeater绑定数组、哈希表、字典 ArrayList/HashTable,Dictionary为datasource

    原文发布时间为:2009-11-19 —— 来源于本人的百度文章 [由搬家工具导入]

    repeater绑定数组、哈希表、字典
    datasource为ArrayList/HashTable,Dictionary时,范例

    Default7.aspx 前台页面:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default7.aspx.cs" Inherits="Default7" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title>http://hi.baidu.com/handboy</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    绑定数组
    <hr />
    <ul>
    <asp:Repeater ID="repArray" runat="server">
    <ItemTemplate>
    <li>
    <%#Container.DataItem %>
    </li>
    </ItemTemplate>
    </asp:Repeater>
    </ul>
    绑定Hashtable
    <hr />
    <ul>
    <asp:Repeater ID="repHash" runat="server">
    <ItemTemplate>
    <li>
    Key:<%#Eval("key") %>,Value:<%#Eval("value") %>
    </li>
    </ItemTemplate>
    </asp:Repeater>
    </ul>

    </div>
    </form>
    </body>
    </html>

    Default7.cs 后台页面:

    using System;
    using System.Web.UI.WebControls;
    using System.Collections;

    public partial class Default7 : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    BindArray();//绑定数组
    BindHashtable();//绑定哈希表,绑定Dictionary<>跟哈希表一样           
    }

    }

    protected void BindArray()
    {
    ArrayList arr = new ArrayList();
    arr.Add("arr11111111111");
    arr.Add("arr22222222222");
    arr.Add("arr33333333333");
    arr.Add("arr44444444444");

    repArray.DataSource = arr;
    repArray.DataBind();
    }

    protected void BindHashtable()
    {
    Hashtable hash = new Hashtable();
    hash.Add(11,"hash11111111111");
    hash.Add(22,"hash22222222222");
    hash.Add(33,"hash33333333333");
    hash.Add(44,"hash44444444444");

    repHash.DataSource = hash;
    repHash.DataBind();
    }

    }
  • 相关阅读:
    ibatis resultMap 结果集映射
    iabtis初探
    struts2获取请求参数的三种方式及传递给JSP参数的方式
    Struts2的运行机制简介
    Spring AOP面向切面编程的实现
    java 单例模式及getInstance的好处
    It is indirectly referenced from required .class files
    AngularJS学习篇(二)
    AngularJS学习篇(一)
    Flex布局语法
  • 原文地址:https://www.cnblogs.com/handboy/p/7158343.html
Copyright © 2011-2022 走看看