Sorry if this is not the correct way to submit changes, but have run into an issue and found what I believe is the correct fix.
(nb:Tried to select the component but couldnt, so had to put in title)
When using the CascadingDropDown I needed to add some custom attributes to each listItem
To do this I decided to pass back JSON data in the items value property.
This all works fine, but then when trying to get the knownCategoryValues I run into problems if I use the built in ParseKnownCategoryValuesString.
Looking at the source, this is because the string is being split on ; and then each item on :
Where the value of my drop down contains my JSON data this fails for the following knownCategoryValues string:
Media:1;Client:{"Name":"ABC","Id":123,"Code":"ABC","Currency":"EUR"};
I created a slightly modified version of this that handles this scenario, but shoudl not affect others where we look for the first occurance of the : seperator and parse that way. The modified lines are marked. I also assume this would break if any of the drop down values contained a colon.
public static System.Collections.Specialized.StringDictionary ParseKnownCategoryValuesString(string KnownCategoryValues)
{
// Validate parameters
if (null == KnownCategoryValues)
{
throw new ArgumentNullException("knownCategoryValues");
}
System.Collections.Specialized.StringDictionary dictionary = new System.Collections.Specialized.StringDictionary();
if (null != KnownCategoryValues)
{
// Split into category/value pairs
foreach (string knownCategoryValue in KnownCategoryValues.Split(';'))
{
// Split into category and value
string[] knownCategoryValuePair = knownCategoryValue.Split(':');
//MODIFIED:check for exactly 2 items breaks if value contains our : seperator
if (knownCategoryValuePair.Length>=2)
{
// Add the pair to the dictionary
//MODIFIED:changed to extract value after the 1st : so wont get confused if value conatins a colon
dictionary.Add(knownCategoryValuePair[0].ToLowerInvariant(),
knownCategoryValue.Substring(knownCategoryValue.IndexOf(":") + 1));
}
}
}
return dictionary;
}
If there is a different / better way of submitting potential bugs / fixes please let me know
Thanks
Comments: I am trying to something similar. [WebMethod] public CascadingDropDownNameValue[] GetPlaces(string knownCategoryValues, string category) { var gids = new List<GID>(); int gidId =6295630; StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //if (!kv.ContainsKey("gid") || !Int32.TryParse(kv["gid"], out gidId)) //{ // return null; //} XDocument request = XDocument.Load(@"http://www.geonames.org/childrenJSON?geonameId=" + Convert.ToString(gidId));// + "&callback=listPlaces&style=long"); //aObj = new JSONscriptRequest(request); //aObj.buildScriptTag(); //aObj.addScriptTag(); List<CascadingDropDownNameValue> gidNames = new List<CascadingDropDownNameValue>(); //try //{ // foreach (var gid in gidList) // { // string strGIDID = gid.; // string strGIDName = gid.Name; // gidNames.Add(new CascadingDropDownNameValue(strRegName, strRegID)); // } //} return gidNames.ToArray(); } Would like to create a web service in C# from JavaScript http://vikku.info/programming/geodata/geonames-get-country-state-city-hierarchy.htm script type="text/javascript"> var whos=null; function getplaces(gid,src) { whos = src // var request = "http://ws.geonames.org/childrenJSON?geonameId="+gid+"&callback=getLocation&style=long"; var request = "http://www.geonames.org/childrenJSON?geonameId="+gid+"&callback=listPlaces&style=long"; aObj = new JSONscriptRequest(request); aObj.buildScriptTag(); aObj.addScriptTag(); } function listPlaces(jData) { counts = jData.geonames.length<jData.totalResultsCount ? jData.geonames.length : jData.totalResultsCount who = document.getElementById(whos) who.options.length = 0; if(counts)who.options[who.options.length] = new Option('Select','') else who.options[who.options.length] = new Option('No Data Available','NULL') for(var i=0;i<counts;i++) who.options[who.options.length] = new Option(jData.geonames[i].name,jData.geonames[i].geonameId) delete jData; jData = null } window.onload = function() { getplaces(6295630,'continent'); } </script> </head> <div class="contents" style="width:55%; margin:0px auto;"> <p><span>Continent:</span> <select name="continent" id="continent" onchange="getplaces(this.value,'country');"> <option value=""></option> </select> </p> <p><span>Country:</span> <select name="country" id="country" onchange="getplaces(this.value,'province');"> <option value=""></option> </select> </p> <p><span>State / Provice:</span> <select name="province" id="province" onchange="getplaces(this.value,'region')"> <option value=""></option> </select> </p> <p><span>County / Region:</span> <select name="region" id="region" onchange="getplaces(this.value,'city')"> <option value=""></option> </select> </p> <p><span>City:</span> <select name="city" id="city"> <option value=""></option></select> </p> </div>
(nb:Tried to select the component but couldnt, so had to put in title)
When using the CascadingDropDown I needed to add some custom attributes to each listItem
To do this I decided to pass back JSON data in the items value property.
This all works fine, but then when trying to get the knownCategoryValues I run into problems if I use the built in ParseKnownCategoryValuesString.
Looking at the source, this is because the string is being split on ; and then each item on :
Where the value of my drop down contains my JSON data this fails for the following knownCategoryValues string:
Media:1;Client:{"Name":"ABC","Id":123,"Code":"ABC","Currency":"EUR"};
I created a slightly modified version of this that handles this scenario, but shoudl not affect others where we look for the first occurance of the : seperator and parse that way. The modified lines are marked. I also assume this would break if any of the drop down values contained a colon.
public static System.Collections.Specialized.StringDictionary ParseKnownCategoryValuesString(string KnownCategoryValues)
{
// Validate parameters
if (null == KnownCategoryValues)
{
throw new ArgumentNullException("knownCategoryValues");
}
System.Collections.Specialized.StringDictionary dictionary = new System.Collections.Specialized.StringDictionary();
if (null != KnownCategoryValues)
{
// Split into category/value pairs
foreach (string knownCategoryValue in KnownCategoryValues.Split(';'))
{
// Split into category and value
string[] knownCategoryValuePair = knownCategoryValue.Split(':');
//MODIFIED:check for exactly 2 items breaks if value contains our : seperator
if (knownCategoryValuePair.Length>=2)
{
// Add the pair to the dictionary
//MODIFIED:changed to extract value after the 1st : so wont get confused if value conatins a colon
dictionary.Add(knownCategoryValuePair[0].ToLowerInvariant(),
knownCategoryValue.Substring(knownCategoryValue.IndexOf(":") + 1));
}
}
}
return dictionary;
}
If there is a different / better way of submitting potential bugs / fixes please let me know
Thanks
Comments: I am trying to something similar. [WebMethod] public CascadingDropDownNameValue[] GetPlaces(string knownCategoryValues, string category) { var gids = new List<GID>(); int gidId =6295630; StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues); //if (!kv.ContainsKey("gid") || !Int32.TryParse(kv["gid"], out gidId)) //{ // return null; //} XDocument request = XDocument.Load(@"http://www.geonames.org/childrenJSON?geonameId=" + Convert.ToString(gidId));// + "&callback=listPlaces&style=long"); //aObj = new JSONscriptRequest(request); //aObj.buildScriptTag(); //aObj.addScriptTag(); List<CascadingDropDownNameValue> gidNames = new List<CascadingDropDownNameValue>(); //try //{ // foreach (var gid in gidList) // { // string strGIDID = gid.; // string strGIDName = gid.Name; // gidNames.Add(new CascadingDropDownNameValue(strRegName, strRegID)); // } //} return gidNames.ToArray(); } Would like to create a web service in C# from JavaScript http://vikku.info/programming/geodata/geonames-get-country-state-city-hierarchy.htm script type="text/javascript"> var whos=null; function getplaces(gid,src) { whos = src // var request = "http://ws.geonames.org/childrenJSON?geonameId="+gid+"&callback=getLocation&style=long"; var request = "http://www.geonames.org/childrenJSON?geonameId="+gid+"&callback=listPlaces&style=long"; aObj = new JSONscriptRequest(request); aObj.buildScriptTag(); aObj.addScriptTag(); } function listPlaces(jData) { counts = jData.geonames.length<jData.totalResultsCount ? jData.geonames.length : jData.totalResultsCount who = document.getElementById(whos) who.options.length = 0; if(counts)who.options[who.options.length] = new Option('Select','') else who.options[who.options.length] = new Option('No Data Available','NULL') for(var i=0;i<counts;i++) who.options[who.options.length] = new Option(jData.geonames[i].name,jData.geonames[i].geonameId) delete jData; jData = null } window.onload = function() { getplaces(6295630,'continent'); } </script> </head> <div class="contents" style="width:55%; margin:0px auto;"> <p><span>Continent:</span> <select name="continent" id="continent" onchange="getplaces(this.value,'country');"> <option value=""></option> </select> </p> <p><span>Country:</span> <select name="country" id="country" onchange="getplaces(this.value,'province');"> <option value=""></option> </select> </p> <p><span>State / Provice:</span> <select name="province" id="province" onchange="getplaces(this.value,'region')"> <option value=""></option> </select> </p> <p><span>County / Region:</span> <select name="region" id="region" onchange="getplaces(this.value,'city')"> <option value=""></option> </select> </p> <p><span>City:</span> <select name="city" id="city"> <option value=""></option></select> </p> </div>