Ok, let's consider a scenario for third dropdown list driven from a database.
It's different data - here it's CarName, models and colors
For second dropdown I have a webservice [WebMethod] in CarsService.cs
Code:
[WebMethod]
public CascadingDropDownNameValue[] GetModelsByCarId(string knownCategoryValues,
string category)
{
// Split the knownCategoryValues on ":" with ";" delimiter
// For the first dropdownlist, the values will be "undefined: id of the dropdownelement"
// ex: "undefined: 13;"
// The string at index 1 will be the CarId selected in the dropdownlist.
string[] _categoryValues = knownCategoryValues.Split(':', ';');
// Convert the element at index 1 in the string[] to get the CarId
int _carID = Convert.ToInt32(_categoryValues[1]);
// Create a List<T> of CascadingDropDownNameValue to hold the CarModels data
List<CascadingDropDownNameValue> _carModels = new List<CascadingDropDownNameValue>();
// Create an instance of CarModels TableAdapter
dsCarModelsTableAdapters.CarModelsTableAdapter _carModelAdapter = new dsCarModelsTableAdapters.CarModelsTableAdapter();
// For each datarow in the DataTable returned by the GetModelsByCarId method, add the modelname and modelid to the List<T>
foreach (DataRow _row in _carModelAdapter.GetModelsByCarId(_carID))
{
_carModels.Add(new CascadingDropDownNameValue(_row["ModelName"].ToString(), _row["ModelId"].ToString()));
}
// convert to array and return the vlaues
return _carModels.ToArray();
}
now, if I create a [WebMethod] for third dropdown right underneath as:
//This is the third dropdown for
// getColorbymodelId
[WebMethod]
public CascadingDropDownNameValue[] GetColorsByModelId(string knownCategoryValues,
string category)
{
// Split the knownCategoryValues on ":" with ";" delimiter
// For the first dropdownlist, the values will be "undefined: id of the dropdownelement"
// ex: "undefined: 13;"
// The string at index 1 will be the CarId selected in the dropdownlist.
string[] _categoryValues = knownCategoryValues.Split(':', ';');
// Convert the element at index 1 in the string[] to get the CarId
int _modelID = Convert.ToInt32(_categoryValues[1]);
// Create a List<T> of CascadingDropDownNameValue to hold the CarColorss data
List<CascadingDropDownNameValue> _carColors = new List<CascadingDropDownNameValue>();
// Create an instance of CarColors TableAdapter
dsCarColorsTableAdapters.CarColorsTableAdapter _carColorAdapter = new dsCarColorsTableAdapters.CarColorsTableAdapter();
// For each datarow in the DataTable returned by the GetModelsByCarId method, add the modelname and modelid to the List<T>
foreach (DataRow _row in _carColorAdapter.GetColorsByModelId(_modelID))
{
_carColors.Add(new CascadingDropDownNameValue(_row["ColorName"].ToString(), _row["ColorId"].ToString()));
}
// convert to array and return the vlaues
return _carColors.ToArray();
}
I get the following two errors:
Error 86 The type or namespace name 'dsCarColorsTableAdapters' could not be found (are you missing a using directive or an assembly reference?) c:\inetpub\wwwroot\WebSiteDDL1\App_Code\CarsServic e.cs 72 9
http://localhost/WebSiteDDL1/
Error 87 The type or namespace name 'dsCarColorsTableAdapters' could not be found (are you missing a using directive or an assembly reference?) c:\inetpub\wwwroot\WebSiteDDL1\App_Code\CarsServic e.cs 72 79
http://localhost/WebSiteDDL1/
>> why does the same work for CarModels, but, not the car colors(3rd dropdown)