0

我是新手,正在使用 Webmatrix (CHTML) 尝试设置一个表单,允许用户使用下拉框选择员工。我想我知道如何列出清单:

@{
var db = Database.Open("DatabaseName") ;
var selectCommand="SELECT ID,Employee FROM Employees";
var selectedData = db.Query(selectCommand);
var columns = new[]{"ID", "Employee"};
var grid = new WebGrid(source: selectedData, defaultSort: "Employee" , rowsPerPage:10,columnNames: columns);  
}
@grid.GetHtml(  )  

我想我知道如何获得一个组合框:

<FORM NAME="myform">
<SELECT NAME="mylist">
<OPTION VALUE="01">Employee01
<OPTION VALUE="02">Employee02
<OPTION VALUE="03">Employee03
<OPTION VALUE="04">Employee04
<OPTION VALUE="05">Employee05 - and so on
</SELECT>
</FORM>

我只想知道如何将表格放入组合框中。如果有人可以展示如何做到这一点,将非常高兴。

4

1 回答 1

2

此代码根据您的表格内容创建一个下拉列表:

@{   
    var db = Database.Open("DatabaseName");
    var selectCommand = "SELECT ID, Employee FROM Employees";
    var selectedData = db.Query(selectCommand); 
} 

<form name="myform" method="post">
    <select name="mylist">
        @foreach(var row in selectedData)
        {
            <option value="@row.ID">@row.Employee</option>
        }
    </select>
</form> 
于 2012-09-07T11:07:30.747 回答