I tried all the methods with hard-coded ,the values i am getting selected for options highlighted, but when i replace hard coded value with hidden values (actual user pre selected values from the database )
it just shows /high light the first value
Please help this is urgent.
below is my code:
- $(function () {
- var hdnvalues = "";
- if ($.trim($('#<%=hfroles.ClientID %>').val() != ""))
- { hdnvalues = $.trim($('#<%=hfroles.ClientID %>').val()); }
- var values = "1,2,3";
-
- $.ajax({
- type: "POST",
- url: "NotificationsNews.aspx/GetRoles",
- data: '{}',
- contentType: "application/json; charset=utf-8",
- dataType: "json",
- success: function (r) {
- var ddlRoles = $("[id*=ddlRoles]");
- $.each(r.d, function ()
- {
- ddlRoles.append($("<option></option>").val(this['Value']).html(this['Text']));
- $.each(values.split(","), function (i, e) {
- $("#ddlRoles option[value='" + e + "']").prop("selected", true);
- });
- });
- }
- });
- });