Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET jQuery
i am calling a jquery function with ajax it will returned the FName,Lname,Address,Email on basic of specified id. It returns the json type object when i am going to assign these values to TextBox ,Getting error. so please help me.
function BindGridView(id) {
    debugger;
    var params = "{ID:'" + id + "'}";
    $.ajax({
        type: "POST",
        url: "InsertoninGridViewusingJQuery.aspx/GetRecords",
        data: params,
        contentType: "application/json",
        dataType: "JSON",
        success: function (data) {
            alert(data.d.length);
            for (var i = 0; i < data.d.length; i++) {
                debugger;
                $("#<%=txtFname.ClientID%>").val(data[i].FName);
                $("#<%=txtLname.ClientID%>").val(UserDetails.LName);
                $("#<%=txtAddress.ClientID%>").val(UserDetails.Address);
                $("#<%=txtEmail.ClientID%>").val(UserDetails.Email);
            }
        }
    });
}
Posted 17-Apr-13 22:33pm
Edited 17-Apr-13 22:39pm
v2
Comments
Prasad Khandekar at 18-Apr-13 3:44am
   
Can you post the JSON response and the error? Does your JSON response contains an array named "d". What is UserDetails?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The problem is data.d contains the data, but you are assigning data like below...
data[i].FName, which will not give you the FirstName.
 
As you are debugging the code, you can see that the value are in data.d.
 
So, you should read like data.d[i].FName, but you have to check whether it is working or not. You can use FireBug of Firefox and use the watch window to evaluate this code and check whether you are getting data or not.
 
And you have used
UserDetails.LName
UserDetails.Address
UserDetails.Email
 
which are not defined.
 
You should have used
data.d[i].LName
data.d[i].Address and
data.d[i].Email respectively.
Comments
Member 9208074 at 18-Apr-13 4:52am
   
thanks i m trying suggest by you.
Tadit Dash at 18-Apr-13 4:55am
   
Ok. And let me know what you found out.
Member 9208074 at 18-Apr-13 5:12am
   
i have chaged according to you but still issue remains same. data.d[i].FName having the records i saw the value by debuging it. When assign these values to textbox but values is not displaying in textbox. $("#<%=txtFname.ClientID%>").val(data.d[i].FName);
Tadit Dash at 18-Apr-13 7:24am
   
So, you are getting value in data.d[i].FName, right ?
Have you checked while debugging whether the textbox is accessed or not. I mean the code
$("#<%=txtFname.ClientID%>") selects the textbox or not...
 
And see if there are any errors in console window of FireBug.
 
Please check and also post all the html and jQuery code here. I will try to find out the problem at my end.

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

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 Afzaal Ahmad Zeeshan 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 18 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100