Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Dynamic DropDown
15/01/2014
04:31
Avatar
backy11
New Member
Members
Forum Posts: 2
Member Since:
15/01/2014
sp_UserOfflineSmall Offline

Hi All,

How to construct and return below object from  server side to bind dropdown column in jqgrid, I am using c#  on server side.

 { '1': 'USA', '2': 'England' };

When  I construct above string at server side and return,  it comes like "{ '1': 'USA', '2': 'England' }" which it considers as a string and not object  { '1': 'USA', '2': 'England' } which is without quotation mark.

15/01/2014
15:38
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

It all depends on how you construct the grid and the function which generates this  "select" string.

Check it.

Regards

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

15/01/2014
16:07
Avatar
backy11
New Member
Members
Forum Posts: 2
Member Since:
15/01/2014
sp_UserOfflineSmall Offline

Hello,

I am using below Ajax call to get data for drop down.  I am not able to return data in the format which dropdowns want

{ '1': 'USA', '2': 'England' }

// Ajax call

 $.ajax({
                async: false,
                contentType: "application/json; charset=utf-8",
                url: url,
                dataType: "json",
                success: function (data)
                {
                      countries =eval( data);// data.d;//(data);
                 },
                 error: function (XMLHttpRequest, textStatus, errorThrown)
                {                           

                      alert("Error in function, countries: " + XMLHttpRequest.status + "\r\n" + textStatus + "\r\n" + errorThrown);
                }
          });

//ServerSide code

 public object  GetCountries()
        {
            var data = "";
            List<testData> lstData = new List<testData>();
            lstData.Add(new testData { Id = "1", country = "USA" });
            lstData.Add(new testData { Id = "2", country = "England" });
            for (int i = 0; i < lstData.Count; i++)
            {

               data = data  +"'" +lstData[i].Id + "'" + ":'" + lstData[i].country+"'" ;
                if (i != lstData.Count - 1)
                    data = data + ',';

            }
           data = "{" + data + "}";
         
         return data;

        }
Above code returns as "{ '1': 'USA', '2': 'England' }" which is string and not an object.  How   do I convert "{ '1': 'USA', '2': 'England' }" to { '1': 'USA', '2': 'England' } on client side?

15/01/2014
16:39
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Your ajax expect json as of the settings.

If you return correct the json string, then the data parameter in the ajax should be a valid JSON object.

You will need not to use eval.

...

                url: url,
                dataType: "json",
                success: function (data)
                {
                      countries = data;
                 },

....

Refer to the jQuery json dataTypes.

Regards

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
69 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information