Results 1 to 12 of 12

Thread: How retrieve data from hash table output

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up How retrieve data from hash table output

    Dear Friends,

    I got a hash table like below i put
    Response Received:
    System.Collections.Hashtable
    Key: http://www.paypal.com
    Value:
    System.Collections.Hashtable
    Key: reselleraccesslevel
    Value:
    AllowAll
    Key: customerallowedpaymenttype
    Value:
    AllowAll
    Key: gatewayname
    Value:
    http://www.paypal.com
    Key: customeraccesslevel
    Value:
    AllowAll
    Key: paymenttypeid
    Value:
    25595
    Key: displayposition
    Value:
    1

    Now i need to retrieve key and value from the output (ie web browser). Is it possible? I am using Asp.Net 2.0 application. Also i need to bind in grid this key and value.

    Hope your's reply.

    Thanks & Regards

    Failing to plan is Planning to fail

  2. #2
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    Thumbs up Re: How retrieve data from hash table output

    hi,

    You can bind hashtables to gridviews.

    For an example, you have a simple hashtable that has all its values as string. You will have to add 2 bound columns for your gridview and set their DataField to the key and value properties of the hash table.

    Code:
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                <Columns>
                    <asp:BoundField DataField="key" HeaderText="key" />
                    <asp:BoundField DataField="value" HeaderText="value" />
                </Columns>
            </asp:GridView>
    Then in your code behind you can do standard

    GridView1.Datasource = YourHashtable;
    GridView1.DataBind();

    Good Luck
    Loving dotnet

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up Re: How retrieve data from hash table output

    Hi

    Actually i have output like a hash table. I need a value and key only.So how to retrieve the key and value from the output ie web browser. Please reply me as soon as. Hope your's reply.

    Thanks & Regards
    Failing to plan is Planning to fail

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up How read a hash table object

    Hi friends,

    I am in problem. I am using Asp.Net 2.0 application.I got an output in hash table like

    System.Collections.Hashtable
    Key: ashok.org
    Value:
    System.Collections.Hashtable
    Key: status
    Value:
    available
    Key: classkey
    Value:
    domorg

    The above hash table output i got it. I want to read this hash table object and i need to get the Key and value both.

    I can create hash table object and using IDictionary i can get these Key and Value. But first time i can get Key and write it. Here my Value is in object type and inside I have Key and Value. How can i read the object?? and get the Key and Value inside of Value. Please give me suggestion. Hope yours reply.
    Failing to plan is Planning to fail

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: How retrieve data from hash table output

    I'm not sure I understand... you have the hashtable so all you need to do is bind it and it'll show up in the output. If that's not it, can you explain in more detail?

  6. #6
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    Re: How read a hash table object

    hi, Try the follwoing code. this code shows the key and values also.
    Code:
    Hashtable exampleTable = new Hashtable();
                exampleTable.Add("txt", "notepad.exe");
                exampleTable.Add("bmp", "paint.exe");
                exampleTable.Add("dib", "paint.exe");
                exampleTable.Add("rtf", "wordpad.exe");
                foreach (string key in exampleTable.Keys)
                {
                    Response.Write(exampleTable[key].ToString(),key);
                }
    Good luck.
    Loving dotnet

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2007
    Posts
    241

    Thumbs up Re: How retrieve data from hash table output

    Hi mendhak,

    Thanks for your reply. Actually i have output

    system.collections.hashtable
    Key: ashok.org
    Value :
    system.collections.hashtable
    Key : status
    Value: Available
    Key: classkey
    Value : demoorg

    I can read using dictionaryentry. But what my problem that while i put foreach i got Key as a string next value as an object that is system.collections.hashtable. After that inside i have key and value.How can i get hastable inside of hashtable value both??

    This is my question. I think that now you got it my doubt.

    Hope your's reply.
    Failing to plan is Planning to fail

  8. #8
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    Smile Re: How retrieve data from hash table output

    hi,

    I replied to you. View this post.

    http://www.vbforums.com/showthread.php?t=556389

    don't Post same threads for two time.

    Good luck.
    Loving dotnet

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: How retrieve data from hash table output

    Threads merged. Please don't double post or cross post... there's no point.

  10. #10
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,173

    Re: How retrieve data from hash table output

    For each item that you get, if you know the type inside, then get the value out and cast it or CType() it to the type you want, in your case, that'd be another HashTable. You then use that as a regular Hashtable to read it.

  11. #11
    New Member
    Join Date
    Jul 2012
    Posts
    1

    Re: How read a hash table object

    IDictionaryEnumerator s = hashtable.GetEnumerator();
    while (s.MoveNext())
    {
    MessageBox.Show(s.Key + s.Value.ToString());
    }

  12. #12
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: How read a hash table object

    Quote Originally Posted by prasad.k539 View Post
    IDictionaryEnumerator s = hashtable.GetEnumerator();
    while (s.MoveNext())
    {
    MessageBox.Show(s.Key + s.Value.ToString());
    }
    Hello,

    Welcome to the forums! Thanks for taking the time to post in this thread!

    One thing I would say though, using MessageBox.Show within an ASP.NET application is not really a recommended best practice. Although it will "work" when you are debugging out of Visual Studio, when you deploy the application onto a server, you will never see the MessageBox appear on the client.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width