ASP.NET code Web方法的背后 [英] ASP.NET Code Behind Web Methods

查看:154
本文介绍了ASP.NET code Web方法的背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我试图通过使用Web服务来过滤一些成果。这是我的HTML code这是我在js文件动态添加的组件:

Basically I am trying to filter some results by using web services. Here is my HTML code which I added the component dynamically in js file:

htmlStr += "<div id='filterContent'><input type='checkbox' id='cbShowAllBus' onClick='getAllBusStop();' /><span class='getBusRouteSubtitle'>Show All Bus Stops</span><br/><br/>";

htmlStr += "<span class='getBusRouteTitle'>Bus Services No.</span><br/>";
htmlStr += "<select id='busservice_option' onchange='filterBusStop(this.value);getFilteredBusStop();' style='width:100%;'><option value='default'>Select Bus Service</option><optgroup label='Trunk Bus Services'><option value='2_2'>2</option><option value='3_2'>3</option><option value='4_1'>4</option></optgroup></select>";

htmlStr += "</div><br/>";

我对复选框和一个下拉列表即可。所以,如果复选框被选中,它会显示所有公交车站的位置无任何筛选条件。

I have on checkbox and a drop down list. So if checkbox is checked, it will show all the bus stop location without any filter criteria.

我所做的是从code后面,我调用哪个执行SQL语句的Web服务方法。然后我绑定的结果成网格视图和提取网格视图的结果。我不会发布codeS这些功能,因为它工作得很好。

What I did is from code behind, I call the web service method which execute the SQL statement. Then I bind the results into a grid view and extract the results from grid view. I will not post the codes for these functions as it works fine.

我的问题发生时,我尝试筛选结果。我用与上述相同的技术。这里是我的asp.net code后面执行SQL语句,并将结果绑定到网格视图:

My problem occured when I try to filter the results. I used the same technique as above. Here is my asp.net code behind to execute the SQL statement and bind the result to grid view:

[System.Web.Services.WebMethod()]
    public void filterBusStop(String filter)
    {
        SgDataService filterBusStop = new SgDataService();

        filterBusStopDGV.DataSource = filterBusStop.GetFilterBusStop(filter);
        filterBusStopDGV.DataBind();

    }

和其中包含的SQL语句我的web服务的方法:

And my web service method which contains the SQL statement:

[WebMethod]
    public DataSet GetFilterBusStop(String filter)
    {
        SqlConnection sqlConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["EasyMoveConnStr"].ConnectionString);
        string select = "select * from dbo.BusStop where B1 LIKE %" + filter + "%";
        sqlConnection1.Open();
        SqlDataAdapter da = new SqlDataAdapter(select, sqlConnection1);
        DataSet ds = new DataSet();
        da.Fill(ds, "FilterBusStop");
        sqlConnection1.Close();
        return (ds);
    }

填充后数据到GridView中,我环通GridView和使用经纬度绘制长每个成果转化为一个图:

After populate the data into gridview, I loop thru the gridview and plot each results into a map by using lat long:

function getFilteredBusStop() {
var Grid_Table = document.getElementById('filterBusStopDGV');
    for (var i = 1; i < Grid_Table.rows.length; i++) {
        var coordXicon = Grid_Table.rows[i].cells[4].textContent;
        var coordYicon = Grid_Table.rows[i].cells[5].textContent;
        var B1 = Grid_Table.rows[i].cells[6].textContent;
        var B2 = Grid_Table.rows[i].cells[7].textContent;

        var point = new esri.geometry.Point({ "x": coordXicon, "y": coordYicon, "spatialReference": { "wkid": 3414 } });
        if (B2 == 1) {
            var symbol = new esri.symbol.PictureMarkerSymbol('img/busIcon.png', 30, 30);
        }
        else {
            var symbol = new esri.symbol.PictureMarkerSymbol('img/busstopicon.png', 30, 30);
        }
        var PointGraphic = new esri.Graphic(point, symbol);
        map.graphics.add(PointGraphic);

        var infoTemplate = new esri.InfoTemplate();

        infoTemplate.setTitle(Grid_Table.rows[i].cells[1].textContent);

        infoTemplate.setContent("<b>Bus Stop Location: </b>" + Grid_Table.rows[i].cells[2].textContent + "<br/>"
        + "<b>Road Name: </b>" + Grid_Table.rows[i].cells[3].textContent + "<br/>"
        + "<b>Buses: </b>" + B1 + "<br/>");

        var graphic = PointGraphic;
        graphic.setSymbol(symbol);
        graphic.setInfoTemplate(infoTemplate);
        busIcon.push(map.graphics.add(graphic));
    }
}

但不知何故,我得到一个错误信息是 filterBusStop未定义。我认为,出现问题时的onchange在下拉列表中,我身后叫Web服务方法code以错误的方式。任何导游?

But somehow, I get an error message which is filterBusStop is undefined. I think the problem occurs when onchange at drop down list, I called the code behind web service method in a wrong way. Any guides?

在此先感谢。很抱歉的超长线,因为我试图解释什么,我试图做的。

Thanks in advance. Sorry for the super long thread as I am trying to explain what I am trying to do.

推荐答案

我不知道把两个呼叫在onchange事件,所以我会离开,现在。

i don't know about putting two calls in the onchange event so i'll leave that for now.

请问有ScriptManager的=的EnablePageMethods真?
如果是这样,请尝试该方法是静态的。
你可能需要做两个

does the scriptmanager have EnablePageMethods="true"? if so, try making the method static. you might have to do both.

这篇关于ASP.NET code Web方法的背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆