Common Custom renderers
Common_CustomRenderers_CSharp\GraduatedColorRenderer.aspx.cs
// Copyright 2011 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.
// 

public partial class GraduatedColorRendererPage : System.Web.UI.Page 
{
  protected void Page_Load(object sender, System.EventArgs e)
  {
    if (!ScriptManager1.IsInAsyncPostBack)
    {
      // Potential inital load. Check if graphics resource has the graphics layer, and if not, create it
      ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem mapResourceItem = 
                MapResourceManager1.ResourceItems.Find("GraphicsDataSource");
      ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource graphicsMapResource = 
                mapResourceItem.Resource as ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource;

      if (graphicsMapResource != null)
      {
                // Check whether the map extent is null, meaning the map has not yet been initialized
        if (Map1.Extent == null)
        {
                    // Forces earlier initialization of map and will set map extent
          ESRI.ArcGIS.ADF.Web.DataSources.IMapResource primaryMapResource = 
                        Map1.PrimaryMapResourceInstance; 
        }

        // Call helper method in App_Code which generates a random graphics layer.  In real-world situations,
                // the random layer could be replaced with, for instance, the result of a query.  Once the layer is
                // created, apply the renderer and add the layer to the graphics resource.

        // First create a polygon layer...
        ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer featureGraphicsLayer = 
                    ESRI.ADF.Samples.Renderers.GenerateGraphicsHelper.CreatePolygonFeatures("polygons", Map1.Extent, 10);
        applyRendererAndAddLayer(graphicsMapResource, featureGraphicsLayer);

        // ...then a polyline layer
        featureGraphicsLayer = 
                    ESRI.ADF.Samples.Renderers.GenerateGraphicsHelper.CreatePolylineFeatures("polylines", Map1.Extent, 10);
        applyRendererAndAddLayer(graphicsMapResource, featureGraphicsLayer);
      }

            // Refresh the graphics resource so the newly added layers show up
      Map1.RefreshResource("GraphicsDataSource");
    }
  }

  // Applies the GraduatedColorRenderer to the graphics layer and adds it to the resource
  private static void applyRendererAndAddLayer(ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource graphicsMapResource, 
        ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer featureGraphicsLayer)
  {
    if (featureGraphicsLayer != null)
    {
            ESRI.ADF.Samples.Renderers.GraduatedColorRenderer graduatedColorRenderer = 
                new ESRI.ADF.Samples.Renderers.GraduatedColorRenderer();
      graduatedColorRenderer.ColorColumnName = "Width"; // Name of column containing the value we want to interpolate
      graduatedColorRenderer.StartColor = System.Drawing.Color.Yellow; // Beginning (low value) of the gradient
      graduatedColorRenderer.EndColor = System.Drawing.Color.Red; // Ending (high value) of the gradient
      graduatedColorRenderer.MinValue = 1; // This value and below will be rendered using Yellow
      graduatedColorRenderer.MaxValue = 6; // This value and above will be rendered using Red
      featureGraphicsLayer.Renderer = graduatedColorRenderer; // Apply renderer to the layer

            // If a layer of the same name has already been added, remove it
      if (graphicsMapResource.Graphics.Tables.Contains(featureGraphicsLayer.TableName))
        graphicsMapResource.Graphics.Tables.Remove(featureGraphicsLayer.TableName); 

            // Add the passed-in layer
            graphicsMapResource.Graphics.Tables.Add(featureGraphicsLayer);
    }
  }
}