Use a hash table to hold URLs then display to GridView

I have not used Hash tables.  My understanding is that people use these to hold IDs from a DB (after referencing a stored proc) then spit out the data in the hash table such as ID, Name, and other fields from the stored proc into a DataGrid....better yet, in my case, I want to spit it out into a GridView.

Tell me, am I correc, this is a technique that is used?  If so, why no datasets?

Anyway, I need help in how to create a class that I could use in C# and a hash table somewhere to do just that.  Populate my GridView in my aspx page.

I'm not sure where to start...I guess create my .cs page or linked library?  Not sure what to do here.  I am new at C#...very novice so please don't assume the simplest is known.  I know how to in the past  populate a  GridView using a Dataset in code-behind but now I'm working in a real OOP environment at a new company trying to figure this out on my own time.
Who is Participating?
Bob LearnedCommented:
Remember that hash tables are meant to provide fast look-up, on the order O(1).  This means that no matter how many items you have in the table, it stays constant on speed of lookup.  It cannot, though, become a data storage structure, since it doesn't respect the order of things.  The hash table stores element in a slot, and uses a repeatable algorithm to calculate where that spot is, and retrieve it very quickly.  So, the key must be unique so that you can lookup a single object.

Using the right tool for the job is very much a part of software development, so it helps to get inside each class structure and get a detailed understanding of the underlying concepts.

HashTable is a data structure to store values with a Key.
The real advantage of it is the Value can be identified using the Key.

EG; You have an employee class, which has many data regarding a particular employee.
       So you are adding the employees into hash table with EmployeeID as Key
      HashTable H = new Hashtable();
      H[“EMP01”] =       <Employee instance>

      By doing so, when you get an employee ID corresponding Employee details can be fetched from hash table with out any looping

EG         <Employee Instance> = H[“EMP01”];

The advantage of Hash table is, it is fast in accessing the Value, If you know a key.

Key and Value of hash table can have of any type
dba123Author Commented:
Yea, so a Hash table is just another way to store data, just like a dataset does right?
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Answer to the second part

Technically the data access and business part has to be on another assemble ( The Ideal OOPS approach)
B’ce the presentation layer (aspx) should be always separated from Business layer. And Presentation layer should only know the business layer, means Business layer should not Know Presentation layer

So in code behind of aspx file should have only the code which link the aspx controls and Business layer and the code to manipulate the presentation.

You can keep the business layer as a separate project in a separate namespace
dba123Author Commented:
so let's say I have a  stored proc:

select EmployeeID, EmployeeName FROM tablename

Then the hash table  will load in the data from the stored proc

Then I can use the hash table as a data source for my GridView and the advantage here is not having to loop?  But you don't loop if you load a data with a dataset either.  I assume a  hash table is more efficient and less resource intensive then?  I just came to a new job for a .com and just have never seen anyone use a hash table for loading DataGrids, etc.  I'm s ure this is a great way to do it, just trying to understand if this is why.  I have read so much about datasets and used datasets that I"m not yet familiar with this approach and why.
dba123Author Commented:
>> Technically the data access and business part has to be on another assemble ( The Ideal OOPS approach)

you are correct, that's how the architecture is setup, also which is sort of new to me...
dba123Author Commented:
so you're saying this (please clarify, I'm new to this complete separation in C# environment):

aspx contains the GridView control obviously
A class contained in a .cs file in the business  layer contains the hash table
The hash table calls the stored proc which brings back the key/value pairs and holds it somehow, I assume in memory?
When the aspx page is loaded, it calls the class, which binds the data in the hash table to the GridView control

In one way you are right, both hashtable and Dataset can store data. But its application /Usage are different.
If I put it another way dattype Integer and string, both can store data, but it’s usage are different

No, You cannot use HashTable as a datasource of any control
Datasource will not allow list like controls
In your scenario the better approach will be using a datareader or dataset/ datatable to bind the data to the control.
dba123Author Commented:
ahh, nevermind, I looked back at a question I had in the interview.  Yes, I'm still using a dataset to bind to the GridView.  I guess they were using a hash table to hold the items the user added to their shopping cart in the example I had to try to code.
Any more clarification required ?
dba123Author Commented:
thanks, yea, I haven't been able to see the code here yet at my new job, just started and don't have VSS installed yet.  I'll have to see how they used hash tables so far and in what situations.

Thanks for the last explanation.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.