Aquí te dejo un código sencillo para acceder a uno de los elementos del Hashtable. Espero te sea de utilidad. Cualquier duda, con gusto te respondo.
Código C#:
Ver originalusing System;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
namespace webappHashtables
{
public partial class _Default : System.Web.UI.Page
{
string name = "";
string str = "";
Hashtable hshTable = new Hashtable();
string[] datos = new string[3];
protected void Page_Load(object sender, EventArgs e)
{
//hshTable.Add("1", "Usuario1");
//hshTable.Add("2", "Usuario2");
//hshTable.Add("3", "Usuario3");
datos[0] = "Telefono";
datos[1] = "direccion";
datos[2] = "oficio";
hshTable.Add("0", datos[0]);
hshTable.Add("1", datos[1]);
hshTable.Add("2", datos[2]);
DataList1.DataSource = hshTable;
DataList1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
if (hshTable.ContainsKey(TextBox1.Text))
{
Label2.Text = "El No. de Llave: " + TextBox1.Text + " ha sido encontrado";
Label3.Text = "Tiene el dato: " + datos[2];
}
}
}
}
Código ASPX:
Ver original<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="webappHashtables._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 id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="No. de Llave: "></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="Buscar" onclick="Button2_Click" />
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
<asp:Label ID="Label3" runat="server" Text=""></asp:Label>
</div>
<div>
<asp:DataList ID="DataList1" runat="server">
<itemtemplate>
<%# DataBinder.Eval(Container.DataItem, "Key", "<font size='1'>{0}</font>") %>
<%# DataBinder.Eval(Container.DataItem, "Value", "<font size='1'>${0:f2}</font>") %>
</itemtemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
Saludos,