Results 1 to 7 of 7

Thread: Getting HTML values into listbox

  1. #1

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Getting HTML values into listbox

    So i have some HTML like this

    <li>
    <div id="1"></div>
    <div id="2"></div>
    <div id="3"></div>
    </li>
    <li>
    <div id="1"></div>
    <div id="2"></div>
    <div id="3"></div>
    </li>
    <li>
    <div id="1"></div>
    <div id="2"></div>
    <div id="3"></div>
    </li>

    Right now i am doing a foreach loop on elements with the <div> tag, then checking if the id="1" if it does add the value to a listbox.

    My problem is, i want to also get div id="2" value at the same time and add it to my listbox, since the Persons ID is in div 1 and the Name of the person is in Div2.

    Any ideas on how to do this?

    I was thinking i could do another for each loop, and just add the username behind the id i pull.
    Question is, how do i add to a value or position in a listbox, after its been filled?
    Last edited by joefox; Apr 28th, 2011 at 06:55 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Getting HTML values into listbox

    where's the html coming from?
    i'd use xdocument if possible

  3. #3

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Getting HTML values into listbox

    Its coming from some static html pages we have on our internal intranetsite
    Last edited by joefox; Apr 28th, 2011 at 07:07 PM.

  4. #4

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Getting HTML values into listbox

    Ok so i have this below

    For Counter As Integer = ListBox1.Items.Count - 1I To 0I Step -1I

    ListBox1.Items.Insert(Counter, ListBox1.Items(Counter).ToString() & "/Joe")

    Next Counter

    I am able to loop through each of the items and update the value in the listbox but problem is it inserts a new item, not updating the current items its on.

    I know im going about this wrong, but any other help would be great.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Getting HTML values into listbox

    vb Code:
    1. For Counter As Integer = ListBox1.Items.Count - 1I To 0I Step -1I
    2.  
    3.     ListBox1.Items(Counter) = ListBox1.Items(Counter).ToString() & "/Joe")
    4.  
    5. Next Counter

  6. #6

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Getting HTML values into listbox

    I dont think my method will work..

    I am assuming that when i do my foreach on the html elments div 2, its going to match the elements found when i put my id's in the first time.

    any other way to do this guys?

    Any way i can look at the <li> items or whats inbetweent hat element and then parse whtas in it?

  7. #7

    Thread Starter
    Frenzied Member joefox's Avatar
    Join Date
    Oct 2004
    Posts
    1,318

    Re: Getting HTML values into listbox

    Edit, i see that for each <li>item i can get its inner html by doing MessageBox.Show(element.InnerHtml.ToString()) i think this might do the trick, since now i get all the elements within that html block.

    Here is some exact html pulled from one my my intranet site pages. (Just changed some of the names )

    <head><title>Employees A</title></head>
    <body>
    <li>
    <div id="1">11</div>
    <div id="2">Tom Jones</div>
    <div id="3">Stage 3</div>
    </li>
    <li>
    <div id="1">12</div>
    <div id="2">Joe Thompson</div>
    <div id="3">Stage 1</div>
    </li>
    <li>
    <div id="1">13</div>
    <div id="2">Billy Blanks</div>
    <div id="3">Stage 9</div>
    </li>
    </body>

    I would like to see something like this in my listbox
    11 / Tom Jones
    12 / Joe Thompson
    13 / Billy Blanks
    Last edited by joefox; Apr 28th, 2011 at 07:45 PM.

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