[我的ASP.net学习历程]Hashtable(DataBind)

类别:Asp 点击:0 评论:0 推荐:
<%@ Page Language="C#" AutoEventWireup="True" Debug="true" %>
<Script language="C#" runat="server">
void Page_Load(Object Sender,EventArgs e){
 Hashtable HT_values=new Hashtable();
 HT_values.Add("1234","Microsoft");
 HT_values.Add("3210","IBM");
 HT_values.Add("4321","SUN");
 HT_values.Add("5623","Orlce");
 
 MyDownList.DataSource=HT_values;
 MyDownList.DataValueField="Key";
 MyDownList.DataTextField="Value";
 
 MyListBox.DataSource=HT_values;
 MyListBox.DataValueField="Key";
 MyListBox.DataTextField="Value";
 
 MyDataGrid.DataSource=HT_values;
 
 Page.DataBind();
}
</Script>
<form id="Form_1" runat="server">
<asp:dropdownlist ID="MyDownList" runat="server"></asp:dropdownlist><br>
<asp:listbox ID="MyListBox" runat="server"></asp:listbox><br>
<asp:datagrid ID="MyDataGrid" runat="server" AutoGenerateColumns="false">
 <columns>
  <asp:boundcolumn HeaderText="Key" DataField="Key"/>
  <asp:boundcolumn HeaderText="Value" DataField="Value"/>
 </columns>
</asp:datagrid>
</form>

本文地址:http://com.8s8s.com/it/it8559.htm