Insert html list of items from database

how to insert elements into html list from database? im using asp c #. i can't make the list on the server because the app doesn't work if i do. so i need to insert values ​​from database into html list. I just need to display 1 column of data. Hooray..

0


source to share


2 answers


You can use Literal, build HTML for the list and set .Text from Literal.



You can either copy the HTML for the list manually or you can create a Listbox in C # and use something like this to have C # export the HTML string to Literal.

+1


source


There are two ways to do this that I can think of:

First, you can put a tag <asp:Placeholder />

on the page and create a list in code:



var select = new HtmlSelect() { Size = 5 };

//assuming the data has been placed in an IEnumarble
foreach (var item in items)
{
    select.Items.Add(new ListItem() { Value = item });
}
selectPlaceholder.Controls.Add(select);

      

Second, you can create a WebService or ashx handler to provide data and populate a list from javascript.

0


source







All Articles