Thanks Emil.
I was able to add your code, and when I got to fully execute I am still not seen the grid in the map.
I am currently facing the following error:
The following is the function i use to make the connection and load the data into the map.
private void LoadAMapFromMsSQL2008()
{
string connectString = "Data Source=dataSource; Initial Catalog=catalog; User ID=id; Password=pass";
MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "table", "index");
sql2008Layer.CustomGeometryColumnName = "item";
sql2008Layer.Open();
//MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "MajorCities", "ID");
sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
sql2008Layer.Open();
sql2008Layer.EditTools.BeginTransaction();
sql2008Layer.EditTools.Add(new PointShape());
sql2008Layer.EditTools.CommitTransaction();
LayerOverlay pointsOverlay = new LayerOverlay("InspectionsLayer");
pointsOverlay.Layers.Add("LayerOfInspectionPoints",sql2008Layer);
Map1.CustomOverlays.Add(pointsOverlay);
//Map1.StaticOverlay.Layers.Add("Sql2008Layer", sql2008Layer);
Map1.CurrentExtent = sql2008Layer.GetBoundingBox();
/*string connectString = "User ID=userid;Password=password;Data Source=192.168.0.178/orcl;";
MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "states", "recid");
sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
Map1.StaticOverlay.Layers.Add("Sql2008Layer", sql2008Layer);*/
}
The following function is what gets called when the user finishes drawing the rectangle:
protected void Map1_TrackShapeFinished(object sender, EventArgs e)
{
// Get the Overlayers.
LayerOverlay staticOverlay = (LayerOverlay)Map1.CustomOverlays[“InspectionsLayer”];
MsSql2008FeatureLayer shapeFileLayer = (MsSql2008FeatureLayer)(staticOverlay.Layers[“LayerOfInspectionPoints”]);
shapeFileLayer.Open();
Feature targetFeature = Map1.EditOverlay.Features[Map1.EditOverlay.Features.Count - 1];
shapeFileLayer.Close();
FeaturesGridView.DataSource = GetDataTableFromFeatures(shapeFileLayer, targetFeature);
FeaturesGridView.DataBind();
}
The other two functions GetDataTableFromFeatures and AddRow are the same as above.
Where i am seeing the error is in either of the lines that I have made bold.
private DataTable GetDataTableFromFeatures(FeatureLayer featureLayer, Feature targetFeature)
{
DataTable dataTable = new DataTable();
featureLayer.Open();
// Add the columns of featurelayer into datatable
**
Collection allColumns = featureLayer.QueryTools.GetColumns();
**
foreach (FeatureSourceColumn column in allColumns)
{
dataTable.Columns.Add(column.ColumnName);
}
// Get the feature within the box.
//RectangleShape box = new RectangleShape(5, 78, 30, 26);
// Set ReturningColumnsType to 'AllColumns', it is important.
**
Collection resultFeature = featureLayer.QueryTools.GetFeaturesWithin(targetFeature, ReturningColumnsType.AllColumns);
**
// Add row for each feature.
foreach (Feature feature in resultFeature)
{
AddRow(dataTable, feature);
}
return dataTable;
}