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