Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从数据库中插入html列表框项_C#_Html_Database_Listbox - Fatal编程技术网

C# 从数据库中插入html列表框项

C# 从数据库中插入html列表框项,c#,html,database,listbox,C#,Html,Database,Listbox,如何将项目从数据库插入html列表框? 我正在使用asp c#。我无法使列表框在服务器上运行,因为如果我这样做,应用程序将无法工作。因此,我必须将数据库中的值插入html列表框。我只需要显示1列数据。干杯。我可以想到两种方法: 首先,您可以在页面上放置标记,并在代码中生成列表框: var select = new HtmlSelect() { Size = 5 }; //assuming the data has been placed in an IEnumarble foreach (va

如何将项目从数据库插入html列表框?
我正在使用asp c#。我无法使列表框在服务器上运行,因为如果我这样做,应用程序将无法工作。因此,我必须将数据库中的值插入html列表框。我只需要显示1列数据。干杯。

我可以想到两种方法:

首先,您可以在页面上放置
标记,并在代码中生成列表框:

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);

其次,您可以创建WebService或ashx处理程序来提供数据并从javascript填充列表。

您可以使用文本,为列表框构建HTML,并设置文本的.Text

您可以将列表框的HTML串在一起,也可以用C语言构建一个列表框,并使用C语言将HTML字符串导出为文本。

将runat=“server”添加到列表框会给您带来什么问题?