0

how do i insert items into an html listbox from a database? im using asp c#. i cant make the listbox run at server because the application wont work if i do that. so i have to insert values from a database into an html listbox. I just need to display 1 column of data. cheers..

1
  • What about adding runat="server" to your ListBox is giving you problems? Commented Nov 15, 2008 at 16:03

2 Answers 2

1

You could use a Literal, build the HTML for the listbox, and set the .Text of the Literal.

You could either string together the HTML for the listbox manually, or you could build a Listbox in C# and use something like this to have C# export the HTML string to the Literal.

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

Comments

0

There are two ways of doing this I can think of:

First, you can place an <asp:Placeholder /> tag on the page and generate the listbox 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 could create a WebService or ashx handler to provide the data and populate the list from javascript.

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.