我有一个带有选择的下拉菜单,我可以在其中设置已完成的下拉菜单的默认值,下次当用户登陆该页面时,我需要显示已保存的下拉菜单
html
<select id="ddlValue" onchange="OnChange()" style="height: 25px;padding: 2px 12px;font-size: 12px;color: #555;background-color: #fff;background-image: none;border: 1px solid #ccc;width:15%;" class="ItemPT5">
<option value="0">All</option>
<option value="2">Value1</option>
<option value="1">Value2</option>
<option value="3">Value3</option>
</select>
jQuery代码-
$.ajax({
type: "GET",
url: webAPIURL + '/GetLoggedinuserId?MemberId=' + UserId,
dataType: "json",
async: true,
cache: false,
traditional: true,
contentType: "application/json; charset=utf-8",
success: function (data) { //getting all the data from controller
if (data.length > 0) { //since length will be greater than 0 it satisfies if conditon
$.each(data.d, function () {
$("#ddlValue").append($("<option/>").val(this.KeyName).text(this.ValueName)); //unable to bind selected value to drop down
});
}
}
});
数据库-
ID DDL_TYPE SELECTED
1 value1 true //should bind value 1 to drop down using jquery since this is saved against the user
2 value2 false
3 value3 false
控制器-
public string GetLoggedinuserId(int MemberId)
{
try
{
esParameters EsPm = new esParameters();
DataTable dt = null;
EsPm.Add(new esParameter("ID", MemberId));
dt = EsPm.FillDataTable("USP_GET");
}
catch (Exception ex) { ex.LogException(); return null; }
return null;
}