求这样一个表:
一个值对应另一个值,并且能拿出来使用.如果不用DataTable用哈希能不能实现?
(我一个页面很多个变量,我想就将遍历一下将控件名与值绑定)
'txtaa','dfadd'
'cbxadf','df21213add'
'txtaad','dfadd'
'txtaad',''

解决方案 »

  1.   

    可以实现键值对的对象很多,hashtable,dictionary ,list<t,t>都可以
      

  2.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!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>无标题页</title>
    </head>
    <body>
        <form runat="server" id="form1">
        
     <asp:TextBox ID="txt" runat="server" />
     <asp:TextBox ID="TextBox1" runat="server" />
     <asp:TextBox ID="TextBox2" runat="server" />
     <asp:TextBox ID="TextBox3" runat="server" />
     <asp:TextBox ID="TextBox4" runat="server" />
     <asp:TextBox ID="TextBox5" runat="server" />
        </form>
        
       
    </body>
    </html>
    \using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text.RegularExpressions;
    using System.Collections.Generic;
    using System.Collections;
    public partial class _Default : System.Web.UI.Page
    {    //using System.Text.RegularExpressions;
        protected void Page_Load(object sender, EventArgs e)
        {        Hashtable hash = new Hashtable();
            hash.Add("TextBox1", "1");
            hash.Add("TextBox2", "2");
            hash.Add("TextBox3", "3");        foreach (DictionaryEntry item in hash)
            {
                try
                {
                    ((TextBox)form1.FindControl(item.Key.ToString())).Text = item.Value.ToString();
                }
                catch
                {            }
            }
        }
    }
      

  3.   

    HASH主要用于信息安全领域中加密算法,它把一些不同长度的信息转化成杂乱的128位的编码,这些编码值叫做HASH值. 也可以说,hash就是找到一种数据内容和数据存放地址之间的映射关系
      

  4.   

    dictionary
    table
    Hashtable 
      

  5.   

    Dictionary<int, int> dict = new Dictionary<int, int>();
                dict.Add(200, 1);
                dict.Add(100, 2);
                dict.Add(50, 3);
                dict.Add(20, 4);
                foreach( KeyValuePair<int,int> entry in dict)
                {
                    Console.WriteLine(
                        string.Format("key:{0}\nvalues:{1}\n",
                                      entry.Key,
                                      entry.Value
                                     )
                    );
                }