Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
Hi friends,

I have a quick question for u:
Actually I am getting data from linq query and now I want to bind this data to the different controls based on the change event of the combo box?

Note:
1. I don't have any grid view.
2. I'm using linq QUERY for getting data.

Thanks in Advance!!
Posted
Updated 27-May-14 11:35am
v2
Comments
Matt T Heffron 27-May-14 18:45pm    
Since this is display-related: Is this for WinForms or WPF or ASP.NET or ???
apr1234 28-May-14 9:38am    
Its is Asp.net

1 solution

You can have a page method which will get the values from database and return in JSON formatted string. You can also use asmx web methods to return the same result.

JavaScript
$('#ddlName').change(function () {
   PopulatePersonDetail($('#ddlName').val());
});


Call the method using jQuery 'ajax' method and get the JSON object which contains the actual values.

JavaScript
function PopulatePersonDetail(){
var name = 'smruti';
$.ajax({
        type: "POST",
        url: "../WebMethods/WebService.asmx/GetPersonDetailsByName",
        data: "{key:'" + name + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function (response) {
            $.each(JSON.parse(response.d), function (key, value) {
                 var result = $.parseJSON(response.d);//result contains all detail
                 $('#txtAge').val(result.Age); // like this all other fields also can be populated.
            });
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            ShowError(failMessage, 450, 100);
        }
    });
}


Here is the web method which is called to get data.
C#
[WebMethod(EnableSession = true)]
        public string GetPersonDetailsByName(string name)
        {
            string jsonData = string.Empty;
            Person personData = new Person();
            List<Person> PersonEntityList = personData.GetPersonDetailsByName(string name);
            jsonData = Parser.EntityToJSon(PersonEntityList);
            return jsonData;
        }


Hope this will definitely be helpful.
 
Share this answer
 
v2
Comments
SRS(The Coder) 3-Jun-14 6:55am    
You have removed this as answer, any problem ?
Can you let me know if in any regards i can help ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900