http://www.gissky.net- GIS空间站

我要投稿 投稿指南 RSS订阅 网站资讯通告:
搜索: 您现在的位置: GIS空间站 >> 技术专栏 >> ArcGIS >> ArcGIS Server >> 正文

ArcGIS Server9.3中应用Gridview分页显示

作者:qingqibi…    文章来源:qingqibing    点击数:    更新时间:2009-12-21
摘要:在arcgis server中使用gridview,在9.2中是比较麻烦的,一方面他会失去状态,只能通过html和js来控制,另外一方面是里面的事件都会不能使用。我们在9.3中我们可以直接把AO分析的结果(DataTable)直接赋值跟gridview的Datasource,然后再做一个简单的databinding就可以。

 arcgis server中使用gridview,9.2中是比较麻烦的,一方面他会失去状态,只能通过htmljs来控制,另外一方面是里面的事件都会不能使用。

1.不再需要RenderControl来交互。
9.2中我们经常使用下面的方法来显示结果。
gv.datasource =...
gv.databind();
string sts;
HtmlTextWriter htw;
using (System.IO.StringWriter sw0 = newSystem.IO.StringWriter())
{

htw = new HtmlTextWriter(sw0);

tv.RenderControl(htw);

htw.Flush();

sts = sw0.ToString();
}

CallbackResult cr0 = new CallbackResult(tv,"content", sts);
map.CallbackResults.Add(cr0);
我们在9.3中我们可以直接把AO分析的结果(DataTable)直接赋值跟gridviewDatasource,然后再做一个简单的databinding就可以。
2.gridview中的服务器端事件可以直接使用。我们会在后来的列子中介绍。
演示列子1.建立环境

打开vs2008建立一个模板代码(省略),在鹰眼代码的前面加如下代码:
<esri:FloatingPanelID="fp1" runat="server" BackColor="White"BorderColor="Gray"

BorderStyle="Solid" BorderWidth="1px"Font-Names="Verdana" Font-Size="8pt"ForeColor="Black"


Height="380px" Title="
框选结果" TitleBarColor="WhiteSmoke"TitleBarHeight="20px"

TitleBarSeparatorLine="False" Transparency="35"Width="600px" Style="position: absolute;


left: 200px; right: 200px;" Visible="true">


<asp:UpdatePanel ID="UpdatePanel2"runat="server">


<ContentTemplate>


<asp:GridViewID="GridView1" runat="server"AutoGenerateDeleteButton="True"


AutoGenerateSelectButton="True" CellPadding="4"


ForeColor="#333333" GridLines="None"



PageSize="5"AllowPaging="True"




onpageindexchanging="GridView1_PageIndexChanging">


<FooterStyleBackColor="#507CD1" Font-Bold="True" ForeColor="White"/>


<RowStyleBackColor="#EFF3FB" />


<PagerStyleBackColor="#2461BF" ForeColor="White"Horiz />


<SelectedRowStyleBackColor="#D1DDF1" Font-Bold="True"ForeColor="#333333" />


<HeaderStyleBackColor="#507CD1" Font-Bold="True"ForeColor="White" />


<EditRowStyleBackColor="#2461BF" />


<AlternatingRowStyleBackColor="White" />


</asp:GridView>



</ContentTemplate>


<Triggers>


<asp:AsyncPostBackTriggerC />


</Triggers>


</asp:UpdatePanel>


</esri:FloatingPanel>


<%--Overview Map--%>


(系统自带代码).........
在工具栏上添加一个工具:

<esri:Tool ClientAction="DragRectangle"DefaultImage="~/images/measure-poly.png"

Disabled="false" JavaScriptFile=""Name="Tool" Text="
测试" ToolTip="测试" ServerActiServerActi />
在default的后台代码添加如下响应事件:

//改变分页序号

protected void GridView1_PageIndexChanging(objectsender, GridViewPageEventArgs e)

{


GridView1.PageIndex = e.NewPageIndex;



GridView1.DataSource = this.Map1.Page.Session["dt"];


GridView1.DataBind();


}

//关闭浮动框的时候,把服务器端缓冲清空


protected voidfp1_Hide(object sender, EventArgs args)


{


this.Map1.Page.Session["dt"] = null;


}


建立一个名字叫select的类,代码如下:

public class select:IMapServerToolAction
{

#region
IMapServerToolAction 成员


publicvoidServerAction(ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgsargs)

{

Mapmap = args.Control as Map;


//取得框参数

RectangleEventArgsrectargs = (RectangleEventArgs)args;

//取得客户端矩形框

System.Drawing.Rectangle myrect = rectargs.ScreenExtent;

ESRI.ArcGIS.ADF.Web.Geometry.Pointminpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(myrect.Left,myrect.Bottom, map.Extent, (int)map.Width.Value,(int)map.Height.Value);

//取得左下角的位置

ESRI.ArcGIS.ADF.Web.Geometry.Point maxpnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(myrect.Right, myrect.Top,map.Extent, (int)map.Width.Value, (int)map.Height.Value);

//取得右上角的位置

ESRI.ArcGIS.ADF.Web.Geometry.Envelopemappoly = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minpnt, maxpnt);

//构成一个几何方框



ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionalitymf = (ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality)map.GetFunctionality(map.PrimaryMapResource);

//取得地图源所具有的功能


ESRI.ArcGIS.ADF.Web.DataSources.IGISResourcegr = mf.Resource;

boolsupported = gr.SupportsFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality));

ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionalityqf;


string[]lids;

string[]lnames;

qf =(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality)gr.CreateFunctionality(typeof(ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality), null);

qf.GetQueryableLayers(null, out lids, out lnames);


//查询

ESRI.ArcGIS.ADF.Web.SpatialFilter sfilter = newESRI.ArcGIS.ADF.Web.SpatialFilter();

sfilter.SearchOrder = SearchOrder.Spatial;

sfilter.MaxRecords = 500;

ESRI.ArcGIS.ADF.Web.Geometry.Geometryg = mappoly as ESRI.ArcGIS.ADF.Web.Geometry.Geometry;

sfilter.Geometry = g;


System.Data.DataTable[] dt = null;

dt = qf.Identify(mf.Name,mappoly, 3, IdentifyOption.AllLayers, lids);


//这里就是绑定gridview的全部代码。

FloatingPanelfp = map.Page.FindControl("fp1") as FloatingPanel;

GridView gv =fp.FindControl("GridView1") as GridView;


gv.DataSource =dt[0];


map.Page.Session["dt"] = gv.DataSource;


gv.DataBind();



fp.Visible = true;

}


#endregion

}

运行效果:

Tags:ArcGIS Server,9.3,Gridview  
责任编辑:gissky
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 中国地图