ADFTutorials_CSharp\UsingCommonAPI\Default.aspx.cs
// Copyright 2010 ESRI // // All rights reserved under the copyright laws of the United States // and applicable international laws, treaties, and conventions. // // You may freely redistribute and use this sample code, with or // without modification, provided you include the original copyright // notice and use restrictions. // // See the use restrictions. // using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs eventArgs) { // Store the TaskResults control in session for use by the custom tool Session["TaskResultsControl"] = TaskResults1; // Add a handler for the resource drop-down's SelectedIndexChanged event DropDownList1.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged); } void DropDownList1_SelectedIndexChanged(object sender, EventArgs eventArgs) { // Clear the layers drop-down DropDownList2.Items.Clear(); // Get the names of queryable layers for the selected resource and add them // to the layers drop-down string[] layerNames = GetQueryableLayerNames(DropDownList1.SelectedItem.Text); for (int i = 0; i < layerNames.Length; i++) DropDownList2.Items.Add(layerNames[i]); } protected void Page_PreRender(object sender, EventArgs eventArgs) { if (DropDownList1.Items.Count == 0) { // Add resource names to the resource drop-down list foreach (ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem mapResourceItem in MapResourceManager1.ResourceItems) DropDownList1.Items.Add(mapResourceItem.Resource.Name); // Get the names of queryable layers for the selected resource and add them // to the layers drop-down string[] layerNames = GetQueryableLayerNames(DropDownList1.SelectedItem.Text); for (int i = 0; i < layerNames.Length; i++) DropDownList2.Items.Add(layerNames[i]); } } private string[] GetQueryableLayerNames(string resourceName) { // Get a reference to the resource ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality commonMapFunctionality = Map1.GetFunctionality(resourceName); ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gisResource = commonMapFunctionality.Resource; // Create a query functionality to use in querying the resource ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality commonQueryFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality) gisResource.CreateFunctionality( typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null); // Get the resource's queryable layers string[] layerIDs = null; string[] layerNames = null; commonQueryFunctionality.GetQueryableLayers(null, out layerIDs, out layerNames); return layerNames; } }