Binding dropdownlist without refresh

347
November 26, 2016, at 7:49 PM

I am adding Category using jquery/ajax.

$.ajax({
        type: "POST",
        url: "Admin.aspx/SaveCategory",
        data: JSON.stringify({ "kategorija": kategorija }),
        datatype: "JSON",
        contentType: "application/json; charset=utf-8",
        success: function (data) {
            if (data.d == "true") {
                //console.log(kategorija);
                kopce.removeClass("btn-default");
                kopce.addClass("btn-success");
                kopce.html("Dodadeno!");
            }
        }

At the WebMethod on the server SaveCategory i have this code, also here i am calling a function for populating the dropdown.

var context = new CategoryEntities();
            var t = new Category //Make sure you have a table called test in DB
            {
               // CategoryId = Guid(),
                CategoryName = kategorija,
            };
            context.Categories.Add(t);
            context.SaveChanges();
            FillDropDown();
            string result = "true";
            return result;

My function for populating dropdown :

public void FillDropDown()
        {
            var context = new CategoryEntities();
            var category = (from c in context.Categories
                            select new { c.CategoryId, c.CategoryName }).ToList();
            DropDownList1.DataValueField = "CategoryId";
            DropDownList1.DataTextField = "CategoryName";
            DropDownList1.DataSource = category;
            DropDownList1.DataBind();     
        }

But function for populating a dropdown does not fire when SaveCategory function is called.

I want to bind/refresh dropdown when category is added. Some help ?

READ ALSO
setting accept-language in header

setting accept-language in header

I am using an API and in the GET request it wants this:

329
How do I update the class of a jQuery Draggable Item with the Parent ID that it's dropped into?

How do I update the class of a jQuery Draggable Item with the Parent ID that it's dropped into?

I have a fiddle here: https://jsfiddlenet/radmktryan/qfghjnm6/

224
How to combine slider range and some values

How to combine slider range and some values

I have multiple slider, and some valuesI want to combine it, but still something wrong

233
query select options do not append to select

query select options do not append to select

receiving a JSOn response in a script

278