0
function DisplayADSearchResults(result) {
var table = "<table id='myTable'>" +
"<tr>" +
"<th style='width:20px;'> </th>" +
"<th style='width:100px;'><b>First Name</b></th>" +
"<th style='width:100px;'><b>Last Name</b></th>" +
"<th style='width:200px;'><b>Email</b></th>" +
"<th style='width:200px;'><b>Login Name</b></th>" +
"<th style='width:200px;'><b>Role</b></th>" +
"</tr>";
for (var counter = 0; counter < result.length; counter++) {
var chkId = 'chkUserSearch' + counter;
var fId = 'fUserSearch' + counter;
var lId = 'lUserSearch' + counter;
var eId = 'eUserSearch' + counter;
var unid = 'unUserSearch' + counter;
var myData = "<tr>" +
"<td><input type='checkbox' id='" + chkId + "' /></td>" +
"<td id='" + fId + "' class='searchFirstName'>" + result[counter].FirstName + "</td>" +
"<td id='" + lId + "' class='searchLastName'>" + result[counter].LastName + "</td>" +
"<td id='" + eId + "' class='searchEmail'>" + result[counter].EmailAddress + "</td>" +
"<td id='" + unid + "' class='searchUn'>" + result[counter].LoginName + "</td>" +
"<td id='" + unid + "' class='searchUn'>" + ddlStaffCategory + "</td>" + //i want do display my "ddlStaffCategory" drop dropdownlist in this column.
"</tr>";
table += myData;
}
table += "</table>";}
我有上述功能,正在使用從搜索結果動態創建一個html表。在我的剃鬚刀視圖中,我有一個已經創建並填充了值的下拉列表。如何複製或插入下拉列表到html表列
是否有人知道我可以如何在每張表格的最後一列中顯示該dropdownlist?
以下是下拉列表源文件。
@Html.DropDownList("ddlStaffCategory", new SelectList(ViewBag.CategoryList as System.Collections.IEnumerable, "Value", "Text"), new { @class = "form-control form-control-dropdown-medium" })
UPDATE
我已經試過@ ADyson的建議如下圖所示(最後2列),但只是打印的HTML作爲純文本而不是作爲一個下拉列表控制
var searchData = "<tr>" +
"<td><input type='checkbox' id='" + chkId + "' /></td>" +
"<td id='" + dId + "' class='searchDomain'>" + userDomain + "</td>" +
"<td id='" + fId + "' class='searchFirstName'>" + result[counter].FirstName + "</td>" +
"<td id='" + lId + "' class='searchLastName'>" + result[counter].LastName + "</td>" +
"<td id='" + eId + "' class='searchEmail'>" + result[counter].EmailAddress + "</td>" +
"<td id='" + unid + "' class='searchUn'>" + result[counter].LoginName + "</td>" +
"<td id='" + unid + "' class='searchUn'>" + "@Html.DropDownList(\"ddlStaffCategory\", new SelectList(ViewBag.CategoryList as System.Collections.IEnumerable, \"Value\", \"Text\"), new { @class = \"form-control form-control-dropdown-medium\"})" + "</td>" +
"<td>@Html.DropDownList(\"ddlStaffCategory\", new SelectList(ViewBag.CategoryList as System.Collections.IEnumerable, \"Value\", \"Text\"), new { @class = \"form-control form-control-dropdown-medium\"})</td>" +
"</tr>";
你可以簡單地串聯剃刀的HtmlHelper代碼到你的HTML字符串。在運行時,它會評估razor語句並輸出一個HTML字符串,當你的JS函數被執行時,它將形成你的表格標記的一部分,就像你已經手動將HTML寫入JS函數一樣。 – ADyson