Gavin Crawley
Gavin Crawley

Reputation: 345

Get items from HTML list using VB.net

I need to get items from a html list from the vb.net code behind in my asp.net web site. Any thoughts on how this can be done? I want to use the list items then in an sql statement to retrieve data from a database.

Im using javascript on the front end to handle drag and drop between these two lists:

<div class="demo">
<table>
<tr>
    <td valign="top"> <ul id="All" class="connectedSortable sortable" style="border:groove" >
      <input name="DEMO" type="text" style="border:hidden; display:table-cell;" value="All Products" />
        <li class="ui-state-default">item1</li>
        <li class="ui-state-default">item2</li>
        <li class="ui-state-default">item3</li>
        <li class="ui-state-default">item4</li>
        <li class="ui-state-default">item5</li>
        <li class="ui-state-default">item6</li>
        <li class="ui-state-default">item7</li>
        <li class="ui-state-default">item8</li>
        <li class="ui-state-default">item9</li>
      </ul>
    </td>
    <td valign="top"><ul id="Selected" class="connectedSortable sortable" style="border:groove">
      <input name="DEMO" type="text" style="border:hidden; display:table-cell;" value="Selected Products" />
      </ul></td>
 </tr>
</table>
</div>

I cannot use the runat="server" option as it removes the javascript drag and drop functionality on the main page. Any help appreciated

Upvotes: 0

Views: 3162

Answers (3)

Tim Schmelter
Tim Schmelter

Reputation: 460108

  1. Make your UL runat=server, then you can access it in codebehind as HtmlGenericControl and get all items(as LiteralControl) with it's Controls-property.
  2. Use a BulletedList server control which has a Items property and will be rendered as an unordered(ul) or ordered(ol) html-list.

Upvotes: 1

Shrieks
Shrieks

Reputation: 141

I am curious about the requirement - if this is text that you have put on the page, cannot you retrieve it from the same location in your code behind?

Anyhow, to answer the question:

You can add the same items with some delimiter to a hidden textbox and read the value of that textbox in your code behind using the delimiter to separate the items.

Upvotes: 1

huMpty duMpty
huMpty duMpty

Reputation: 14460

Your question in not exactly clear for me. But if you talking about retrieving value of li from code behind...

you have to use runat="server" on your list

eg. <li ID="myList" runat="server">My List Item</li>

Upvotes: 1

Related Questions