0

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

1
  • An <input> element shouldn't be nested in a <ul>. Maybe that interferes with it. Unlikely, but you might as well use valid HTML markup to give it a chance. Commented Mar 23, 2012 at 19:28

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

i think using javascript and storing in hidden field does the trick thanks
1

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>

2 Comments

if i put the runat="server" in the drag and drop javascript functionality does not work. I just want the item names in the selected list so i can then convert the names to string format and use in an sql query
if you need to access the elements from code behind, you have to use the runat = "server"
1
  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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.