Lets you wanted to populate an drop down list from an web service:
Add an ASMX component in your VS project and then follow the below steps:
[WebService(Namespace = "http://google.com/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService]
public class AssetsLookupService : System.Web.Services.WebService { private static readonly string AssetsLookupServicePassword = ConfigurationManager.AppSettings["AssetsLookupServicePassword"];
[WebMethod]
public List<AssetDetails> UserAssetsAccepted(string strUserLogon, string strPassword) { if (strPassword.Equals(AssetsLookupServicePassword)) { List<AssetDetails> acceptedAssetDetailsList = new List<AssetDetails>();
List<AssetHistoryItem> acceptedAssetsForOwner = AssetHistoryAdapter.AssetHistoryByOwnerAtStatus(strUserLogon, Common.STATUS_ACCEPTED); // value form the Common class if (acceptedAssetsForOwner.Count > 0) { foreach (AssetHistoryItem assetHistoryItem in acceptedAssetsForOwner) { acceptedAssetDetailsList.Add(new AssetDetails(assetHistoryItem)); //Items added in the List 'acceptedAssetDetailsList' from the 'AssetHistoryItem' Class } }
return acceptedAssetDetailsList; } else throw new Exception("Authentication failure"); }
[WebMethod]
public CascadingDropDownNameValue[] Location(string knownCategoryValues, string category) { List<CascadingDropDownNameValue> values = new List<CascadingDropDownNameValue>();
foreach (Location location in AssetTypeAdapter.AllLocation()) { values.Add(new CascadingDropDownNameValue(location.LocationCode, location.LocId.ToString())); }
return values.ToArray(); }
}
Call the web service from the aspx – follow the below the codes:
<span> <asp:DropDownList ID="ddlLocation" runat="server"> </asp:DropDownList> </span>
<ajax:CascadingDropDown ID="cddLocation" runat="server" UseContextKey="True" Category="Location" LoadingText="[Loading Locations]" PromptText="Please select a Location" TargetControlID="ddlLocation" ServicePath="LookupService.asmx" ServiceMethod="Location"> </ajax:CascadingDropDown>
