function BindRolesDropdownList() {
$.ajax({
type: "Post",
url: "Dashboard.aspx/PopulateSelectRoleList",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$('#ddlRoles').get(0).options.length = 0;
$("#ddlRoles").get(0).options[0] = new Option("Select Role", "-1");
$.each(msg.d, function(index, item) {
$("#ddlRoles").get(0).options[$("#ddlRoles").get(0).options.length] = new Option(item.Display, item.Value);
});
}
});
}
function BindDropdownList() {
BindRolesDropdownList();
}
[WebMethod]
public static ArrayList PopulateSelectRoleList()
{
//ArrayList lst = new ArrayList();
//lst = DataAccess.DataAccess.GetRolesArrayList();
//for (int i = 0; i < lst.Count; i++)
//{
//}
//return lst;
return new ArrayList()
{
new { Value = 1, Display = "Male" },
new { Value = 2, Display = "Female" }
};
}
public static ArrayList GetRolesArrayList()
{
ArrayList aryList = new ArrayList();
DataSet ds = new DataSet();
ds = DBUtility.SQLExecuteDataset("select * from ST_Roles");
foreach (DataRow row in ds.Tables[0].Rows)
{
aryList.Add(row);
}
return aryList;
}
上面选择的选项列表是它填补我的选择选项的代码,我的问题是如何通过ArrayList的迭代,并从数据库返回的值,而不是在我的代码部分传递的静态值评论说。填充从ArrayList中
你试过了什么?你有什么麻烦? – SLaks
在这里看:http://stackoverflow.com/questions/7895205/creating-dropdown-selectoption-elements-with-javascript/7895287#7895287 – Sam
我从数据库的值到arraylist,如果你看看注释部分下面的代码有返回类型的ArrayList。我希望我的数据库中的ArrayList能够以这种格式返回新的ArrayList() { {value = 1,Display =“Male”}, new {Value = 2,Display =“Female”} }; – Tan