Click here to Skip to main content
16,021,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

how to view the data one by one in hashtable. for example when i click the "Next" button then show data one by one.
Posted

C#
Hashtable ht = new Hashtable();
ht.Add("0", "One");
ht.Add("1", "Two");
ht.Add("2", "Three");
ht.Add("3", "Four");
  int i=1;
private void button1_Click(object sender, RoutedEventArgs e)
        {
        string in="\""+i+"\"";
        txtObjects.Text =i.tostring();
          txtValues.Text = ht[in] ;
          i = (ht.Count % i) + 1;
        }
 
Share this answer
 
Quote:
Hi,

Generally Hashtable is used to store data in the format of Key and Value pairs.
Assume that we are going to add data to Hashtable like this.


Hashtable ht = new Hashtable();
ht.Add("1", "One");
ht.Add("2", "Two");
ht.Add("3", "Three");
ht.Add("4", "Four");

The elements in the Hashtable can be accessed using DictionaryEntry class like
foreach (DictionaryEntry de in ht)
{
txtObjects.Text = txtObjects.Text + "," + de.Key.ToString();
txtValues.Text = txtValues.Text + "," + de.Value.ToString();
}


where txtObjects and txtValues are the ID of the control in .aspx page

 
Share this answer
 
You may iterate on Values[^] collection.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900