ArcGIS.Server.9.2.DotNet自带例子分析(七、一)
目的:
1.arcgis server9.2 ADF实现Query查询功能。
准备工作:
1.用ArcGis Server Manager或者ArcCatalog发布一个叫usa的Map Service,并且把这个Service启动起来。
2.找到DeveloperKit\SamplesNET\Server\Web_Applications目录下的Common_QueryNewWindowCSharp.zip。
开始:
1.新建名为QueryNewWindow的ASP.NET Web应用程序, 然后在页面上添加MapResourceManager1、Button1。设置MapResourceManager1的属性Type:ArcGIS Server Local;Resource:(default)@usa;Data Source:mycomp。Button1添加Button1_Click时间,具体代码和说明如下:
1
protected void Button1_Click(object sender, EventArgs e)
2
{
3
//获取MapResourceManager1的Resource集合
4
IEnumerator egrc = MapResourceManager1.GetResources().GetEnumerator();
5
//判定初始化MapResourceManager1
6
if (!MapResourceManager1.Initialized)
7
{
8
MapResourceManager1.Initialize();
9
}
10
while (egrc.MoveNext())
11
{
12
//随机数
13
Random random = new Random();
14
int randout = random.Next(0, 1000);
15![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
//获取Resource
17
IGISResource gisresource = (IGISResource)egrc.Current;
18
//判定初始化Resource
19
if (!gisresource.Initialized)
20
{
21
gisresource.Initialize();
22
}
23
//判定是否支持QueryFunctionality
24
bool supportquery = gisresource.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));
25
if (supportquery)
26
{
27
//创建QueryFunctionalit
28
ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qfunc;
29
qfunc = (ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gisresource.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);
30![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
//查询图层id和名称
32
string[] lids;
33
string[] lnames;
34
qfunc.GetQueryableLayers(null, out lids, out lnames);
35
//要查询目标图层名称
36
string sourcelayername = "states";
37
//获取查询目标图层的index
38
int layer_index = 0;
39
for (int i = 0; i < lnames.Length; i++)
40
{
41
if (lnames[i] == sourcelayername)
42
{
43
layer_index = i;
44
break;
45
}
46
}
47
//查询过滤
48
ESRI.ArcGIS.ADF.Web.QueryFilter queryfilter = new ESRI.ArcGIS.ADF.Web.QueryFilter();
49
//要查询字段名称
50
string fieldlist = "STATE_NAME";
51
//查询的字段集
52
ESRI.ArcGIS.ADF.StringCollection strcollection = new ESRI.ArcGIS.ADF.StringCollection(fieldlist, ',');
53
queryfilter.SubFields = strcollection;
54
//查询语句
55
queryfilter.WhereClause = "STATE_NAME LIKE 'A%'";
56
//查询结果存入DataTable
57
System.Data.DataTable qdatatable = qfunc.Query(null, lids[layer_index], queryfilter);
58
qdatatable.Columns[0].ColumnName = "STATE_NAME_ALIAS";
59
//查询结果DataTable存入Session中
60
Session["dt" + randout] = qdatatable;
61
}
62![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
string argval = "?id=" + randout;
64
//弹出新页面显示查询结果
65
Response.Write("<script>window.open('TableDialog.aspx" + argval + "', '" + randout.ToString() + "', 'dependent=yes ,width=400, height=200, status=no, toolbar=no, menubar=no, location=no, resizable=yes, scrollbars=yes'); </script>");
66
}
67
}
2.新建TableDialog.aspx页面用来作为弹出页面显示查询结果,在html里面添加一个<div id="datadiv" runat="server"></div>用来显示查询内容。![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
20
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
21
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
23
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
25
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
27
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
28
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
30
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
31
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
32
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
33
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
34
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
35
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
36
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
37
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
38
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
39
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
40
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
41
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
42
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
43
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
44
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
45
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
46
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
47
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
48
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
49
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
50
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
51
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
52
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
53
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
54
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
55
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
56
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
57
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
58
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
59
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
60
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
61
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
62
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
63
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
64
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
65
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
66
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
67
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
3.接下来编写 TableDialog.aspx的Page_Load事件,进行查询内容的显示,具体代码和说明如下:
1
protected void Page_Load(object sender, EventArgs e)
2
{
3
string id = Request.QueryString["id"];
4
DataTable dt = (DataTable)Session["dt" + id];
5
if (dt != null)
6
{
7
System.Web.UI.HtmlControls.HtmlForm htmlform = (System.Web.UI.HtmlControls.HtmlForm)Page.FindControl("form1");
8
Control controldiv = htmlform.FindControl("datadiv");
9![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
GridView gd = new GridView();
11
gd.DataSource = dt;
12
gd.DataBind();
13
gd.Visible = true;
14
gd.BorderWidth = 10;
15
controldiv.Controls.Add(gd);
16
}
17
}
4.这样就可以运行查看效果了,这个例子比较简单了。![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/images/cnblogs_com/hll2008/xxxx.jpg)