Common Custom renderers
Common_CustomRenderers_VBNet\GraduatedColorRenderer.aspx.vb
' 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.
' 

Imports Microsoft.VisualBasic
Imports System
Public Partial Class GraduatedColorRendererPage
  Inherits System.Web.UI.Page
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    If (Not ScriptManager1.IsInAsyncPostBack) Then
      ' Potential inital load. Check if graphics resource has the graphics layer, and if not, create it
      Dim mapResourceItem As ESRI.ArcGIS.ADF.Web.UI.WebControls.MapResourceItem = MapResourceManager1.ResourceItems.Find("GraphicsDataSource")
      Dim graphicsMapResource As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource = TryCast(mapResourceItem.Resource, ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource)

      If Not graphicsMapResource Is Nothing Then
        ' Check whether the map extent is null, meaning the map has not yet been initialized
        If Map1.Extent Is Nothing Then
          ' Forces earlier initialization of map and will set map extent
          Dim primaryMapResource As ESRI.ArcGIS.ADF.Web.DataSources.IMapResource = Map1.PrimaryMapResourceInstance
        End If

        ' 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...
        Dim featureGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.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)
      End If

      ' Refresh the graphics resource so the newly added layers show up
      Map1.RefreshResource("GraphicsDataSource")
    End If
  End Sub

  ' Applies the GraduatedColorRenderer to the graphics layer and adds it to the resource
  Private Shared Sub applyRendererAndAddLayer(ByVal graphicsMapResource As ESRI.ArcGIS.ADF.Web.DataSources.Graphics.MapResource, ByVal featureGraphicsLayer As ESRI.ArcGIS.ADF.Web.Display.Graphics.FeatureGraphicsLayer)
    If Not featureGraphicsLayer Is Nothing Then
      Dim graduatedColorRenderer As ESRI.ADF.Samples.Renderers.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) Then
        graphicsMapResource.Graphics.Tables.Remove(featureGraphicsLayer.TableName)
      End If

      ' Add the passed-in layer
      graphicsMapResource.Graphics.Tables.Add(featureGraphicsLayer)
    End If
  End Sub
End Class