在arcgis 9.3中应用Gridview分页显示

arcgis 9.3中应用Gridview分页显示

arcgis改变

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

1.不再需要RenderControl来交互。

9.2中我们经常使用下面的方法来显示结果。

gv.datasource =...

gv.databind();

string sts;

HtmlTextWriter htw;

using (System.IO.StringWriter sw0 = new System.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:FloatingPanel ID="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" onhide="fp1_Hide">

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

            <ContentTemplate>

                <asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True"

                    AutoGenerateSelectButton="True" CellPadding="4"

                    ForeColor="#333333" GridLines="None" onrowediting="GridView1_RowEditing"

                    PageSize="5" AllowPaging="True"

                    onpageindexchanged="GridView1_PageIndexChanged"

                    onpageindexchanging="GridView1_PageIndexChanging">

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

                    <RowStyle BackColor="#EFF3FB" />

                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />

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

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

                    <EditRowStyle BackColor="#2461BF" />

                    <AlternatingRowStyle BackColor="White" />

                </asp:GridView>

            </ContentTemplate>

            <Triggers>

                <asp:AsyncPostBackTrigger ControlID="GridView1" />

            </Triggers>

        </asp:UpdatePanel>

    </esri:FloatingPanel>

    <%--Overview Map--%>

         (系统自带代码).........

在工具栏上添加一个工具:

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

                                Disabled="false" JavaScriptFile="" Name="Tool" Text="测试" ToolTip="测试" ServerActionClass="select" ServerActionAssembly="App_Code" />

在default的后台代码添加如下响应事件:

 

//改变分页序号

   protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

    {

        GridView1.PageIndex = e.NewPageIndex;

 

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

        GridView1.DataBind();

    }

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

   protected void fp1_Hide(object sender, EventArgs args)

    {

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

    }

 

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

using System;

using System.Data;

using System.Configuration;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

using ESRI.ArcGIS.ADF.Web.UI.WebControls.Tools;

using ESRI.ArcGIS.ADF.Web.UI.WebControls;

using ESRI.ArcGIS.ADF.Web;

 

/// <summary>

///select 的摘要说明

/// </summary>

public class select:IMapServerToolAction

{

         public select()

         {

                   //

                   //TODO: 在此处添加构造函数逻辑

                   //

         }

 

    #region IMapServerToolAction 成员

 

    public void ServerAction(ESRI.ArcGIS.ADF.Web.UI.WebControls.ToolEventArgs args)

    {

        Map map = args.Control as Map;

 

        //取得框参数

        RectangleEventArgs rectargs = (RectangleEventArgs)args;

        //取得客户端矩形框

        System.Drawing.Rectangle myrect = rectargs.ScreenExtent;

        ESRI.ArcGIS.ADF.Web.Geometry.Point minpnt = 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.Envelope mappoly = new ESRI.ArcGIS.ADF.Web.Geometry.Envelope(minpnt, maxpnt);

        //构成一个几何方框

 

 

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

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

 

        ESRI.ArcGIS.ADF.Web.DataSources.IGISResource gr = mf.Resource;

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

        ESRI.ArcGIS.ADF.Web.DataSources.IQueryFunctionality qf;

 

        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 = new ESRI.ArcGIS.ADF.Web.SpatialFilter();

        sfilter.SearchOrder = SearchOrder.Spatial;

        sfilter.MaxRecords = 500;

        ESRI.ArcGIS.ADF.Web.Geometry.Geometry g = 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的全部代码。

        FloatingPanel fp = 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

}

 

运行效果:


点击分页可以看到:

同时我们可以点击选择按钮,我们发现整个一行被加亮:

 

 

上面说明一个问题,此时这个gridview是有状态的。

posted on 2008-07-31 17:55  【轻骑兵】  阅读(1112)  评论(1)    收藏  举报

导航