Common Custom controls
Common_CustomControls_VBNet\CustomControlsWebSite\AddWebPartOnClick.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

Partial Public Class AddWebPartOnClick
    Inherits System.Web.UI.Page
    ' Initializes a MapWebPart and adds it to the page when the Add MapWebPart button is clicked
    Protected Sub btnAddMapWebPart_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim mapWebPart As ADFWebPart_VBNet.MapWebPart = New ADFWebPart_VBNet.MapWebPart()
        mapWebPart.ID = System.Guid.NewGuid().ToString()
        mapWebPart.DataSourceType = "ArcGIS Server Internet"
        mapWebPart.DataSource = "http://serverapps.esri.com/arcgis/services"
        mapWebPart.ResourceDefinition = "Layers@SamplesNet/NorthAmerica"

        WebPartManager1.AddWebPart(mapWebPart, WebPartZone1, 0)
    End Sub

    ' Initializes a MapGridViewWebPart and adds it to the page when the Add MapGridViewWebPart button is clicked
    Protected Sub btnAddMapGridViewWebPart_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim mapGridViewWebPart As ADFWebPart_VBNet.MapGridViewWebPart = New ADFWebPart_VBNet.MapGridViewWebPart()
        mapGridViewWebPart.ID = System.Guid.NewGuid().ToString()
        mapGridViewWebPart.DataSourceType = "ArcGIS Server Internet"
        mapGridViewWebPart.DataSource = "http://serverapps.esri.com/arcgis/services/SamplesNET"
        ' SanFrancisco.mxd in <ArcGIS Developer Kit Install>\Samples\data\SanFrancisco
        mapGridViewWebPart.ResourceDefinition = "1@Layers@SanFrancisco"
        mapGridViewWebPart.DataLayerName = "customers"
        mapGridViewWebPart.GeometryServiceUrl = "http://serverapps.esri.com/arcgis/services/Geometry/GeometryServer"

        ' Initialize a NameValueCollection to specify how we want fields to be displayed.  This specifies the
        ' field display for both the WebPart's GridView and callouts when features are hovered over.
        Dim fieldsCollection As System.Collections.Specialized.NameValueCollection = New System.Collections.Specialized.NameValueCollection()
        fieldsCollection.Add("NAME", "Site Name")
        fieldsCollection.Add("ADDRESS", "Address")
        fieldsCollection.Add("SALES", "Sales")

        mapGridViewWebPart.DisplayFields = fieldsCollection

        WebPartManager1.AddWebPart(mapGridViewWebPart, WebPartZone1, 0)
    End Sub

    ' Removes all Webparts from the page
    Protected Sub btnRemoveWebParts_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        For Each webPart As System.Web.UI.WebControls.WebParts.WebPart In WebPartManager1.WebParts
            WebPartManager1.DeleteWebPart(webPart)
        Next webPart
    End Sub
End Class