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();
    }

    }
  • 相关阅读:
    Oracle中有大量的sniped会话
    Error 1130: Host '127.0.0.1' is not allowed to connect to this MySQL server
    汉字转换为拼音以及缩写(javascript)
    高效率随机删除数据(不重复)
    vs2010 舒服背景 优雅字体 配置
    mvc中的ViewData用到webfrom中去
    jquery ajax return值 没有返回 的解决方法
    zShowBox (图片放大展示jquery版 兼容性好)
    动感效果的TAB选项卡 jquery 插件
    loading 加载提示······
  • 原文地址:https://www.cnblogs.com/handboy/p/7158343.html
Copyright © 2011-2022 走看看